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. 🙂
Thanks for sharing, appreciate it. Guess I’m part of the 2% 😉
Very gold, thanks!
For SSH, you can use your
.ssh/config
file to specify short names for hosts. Here’s mine as an example.For
cd
short-handing, I imaginebash
has an equivalent forcsh
‘scdpath
.Nope! that is cool and I am now using it.
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:
Was just trying to figure this out the other day. Thanks!
I was wondering how you can move those functions (ex and src) to their own files under ~/bin/?
then what do we change in bashrc to run them?
thanks
@Nizzy
If you put them in ~/bin/shortcuts, then just add
. ~/bin/shortcuts
to ~/.bashrc and that should do the trick.