Assuming you are using the bash
shell, take a look at pushd
and popd
. These are two very unsung commands that are helpful in cases like this. pushd
pushes the current working directory onto a stack and then does a cd
to the directory you specify. popd
will then pop the top directory from that stack and cd
to it. Using these your alias would be:
alias vagrants_up=`pushd ~/Vagrant && vagrant up && popd`
These are very handy for interactive use, too. I alias cd
to pushd
and bk
to popd
and find that my workflow is less cluttered when I only have to think of going 'b'ac'k' one or two or three directory changes that I don't have to spell out rather than typing directory names all the time.