Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: directory alias



I make variables for directories I use a lot

db="$HOME/Dropbox"

bin="$db/bin"

and then I can use that to either move files (mv foo $bin) or 'cd' to them
just by typing the variable "$db" and hitting enter.

But if that's what you mean by a "universal alias", then you'd have to do
something else.

You could make your own `cd` function

function cd {

if [ "$#" = "0" ]
then
# if no arg, go to $HOME
 chdir "$HOME"
else
 if [ -d "$@" ]
then
# if the arg is a valid directory, go there
 chdir "$@"
else
case "$@" in
 bar)
chdir  /usr/local/some/path/bar
;;

foo)
chdir ~/some/deep/directory/tree/foo

;;
 *)
echo "chdir: no such file or directory: $@"
 return 1
;;
esac
 fi
fi
}




On Tue, Dec 3, 2013 at 10:21 PM, shawn wilson <ag4ve.us@xxxxxxxxx> wrote:

> not sure if this is really a 'zsh thing' but I'm looking for a way to
> create aliases for a command. I don't want a bunch of symlinks in my
> home directory, and I don't want a universal alias for each directory
> I commonly cd into. What I want is a way to do:
> cd foo
> and it go to ~/some/deep/directory/tree/foo
> and
> cd bar
> and it go to /usr/local/some/path/bar
>
> Is there some zsh-ism (or better bash-ism that also works in zsh so
> that this works on systems I maintain without zsh) to do this without
> symlinks?
>


Messages sorted by: Reverse Date, Date, Thread, Author