I set up a bunch of aliases in my ~/.profile a while back, stuff like this:
alias ex1="ssh ex1.example.com"alias src="cd ~/Sites/src"
Since I use the command line interface to Subversion (I normally prefer a GUI, but for SVN I think the command line is actually faster), I’ve been navigating my source directories more and more often.
Tonight I learned about bash functions - which have now replaced almost all of my aliases.
ex () { ssh $1.example.com ; }src () { cd ~/Sites/src/$1/trunk ; }
Now I can do stuff like this:
ex ex1
and it becomes:
ssh ex1.example.com
and:
src tasks
becomes:
cd ~/Sites/src/tasks/trunk
Probably 70% of you our there don’t care, and 28% already knew this, but for that remaining 2%… this should be gold.
Popularity: 6% [?]
matt adds this Comment:
Thanks for sharing, appreciate it. Guess I’m part of the 2%
January 12th, 2006 at 8:22 am
Ian adds this Comment:
Very gold, thanks!
January 12th, 2006 at 8:40 am
Edward O'Connor adds this Comment:
For SSH, you can use your
.ssh/configfile to specify short names for hosts. Here’s mine as an example.For
cdshort-handing, I imaginebashhas an equivalent forcsh’scdpath.January 12th, 2006 at 12:19 pm
ConĂ¡nn adds this Comment:
Nope! that is cool and I am now using it.
January 14th, 2006 at 2:04 pm
Don Mitchell adds this Comment:
Bash does have a CDPATH env variable you can set to make switching directories easier. It’s a path style variable so you set it to a list of directories and then any cd command will check that list of PATHs to find the first match and put you into that directory. So given the above src() function, you could set CDPATH to something likie:
export CDPATH=.:~/sro/trunk:
January 14th, 2006 at 11:30 pm
Maarten adds this Comment:
Was just trying to figure this out the other day. Thanks!
January 19th, 2006 at 12:47 pm