Creating Mac OS terminal shortcuts
Solution 1
You need to look at bash aliases.
Try adding the following to either your .profile
or .bashrc
or .bash_profile
:
alias star='cd source/alpha/beta/star'
Any command-line editor (eg vi
or emacs
) will work, as would any text editor for the Mac. Aliases work on all Unix-like environments (SunOS, Mac OS X, Linux, AIX, etc).
Then exit Terminal, and when you restart, it should be there. (Alternatively, you can source the script file, but I've found restarting bash
to be better.)
Solution 2
You want to make aliases. Here's an easy way to make an alias without having to open up the .bashrc file. Just save this script into a file called mkalias and then move it to your usr binary directory (I believe that is ~/bin
for OSX). Then run chmod +x mkalias
on the file. Now whenever you want to create an alias you just type: mkalias myalias='my commands'
.
#!/bin/bash
# path to .bashrc, .zshrc, etc.
export RC='~/.bashrc'
if [ `expr index "${1:-0}i" =` == 0 ]; then
echo "Usage: mkalias ALIAS=EXPRESSION
Makes alias permanent by writing to .bash_aliases contained in home directory."
else
# Export alias
echo 'alias '$1 >> $RC
fi
and to answer your question now, just type:
alias star='cd /path/where/you/want/to/go'
Solution 3
Try this applescript on for size:
do shell script "open -a Terminal.app"
tell application "Terminal"
do script "cd /path/to/my/directory"
end tell
That should open a Terminal for you and take you into your directory. You can shortcut it to your desktop, or maybe create a shortcut for it.
Related videos on Youtube
Abdallah Eid
Updated on September 18, 2022Comments
-
Abdallah Eid almost 2 years
Possible Duplicate:
How to build a custom command with optionsI want to create a terminal short that takes me to a deeply-nested folder. For example, I just want to type in "star" every time I open the terminal to take me to cd source/alpha/beta/star.
I find it hard to believe this question hasn't been asked, but I can assure you haven't found the exact step-by-step solution. If you could let me know how to, or just point me to an existing answer, I'd appreciate.
-
JdeBP about 13 years... unless someone remembers that, unlike in that case, aliases aren't the only possible answer here, and tells the poor questioner about the
CDPATH
variable. (-:
-
-
Abdallah Eid about 13 yearshow to you add to ~/.bashrc?
-
Ignacio Vazquez-Abrams about 13 yearsOpen it in a text editor. It's a plain text file.
-
Joe Internet about 13 yearsThe . indicates that the file is hidden, so you can enable hidden files in your finder, or ls -a to see what's there. Edit as any other text file.
-
Paul Mason about 11 yearsCan you please point out where .profile, .bashrc and .bash_profile are located? Thanks
-
David Yates about 11 years@PaulMason - they're where they are in any *nix-like environment: in your home directory when you open your console.