I think I might be able to help with this one! Here's a little trick I learned from a friend. It's also tab completable.
I keep all my code in ~/code
$ c # cd to ~code
$ c pr<tab> # tab complete to c projectname
$ c projectname # cd to ~/code/projectname
This is pretty simple in zsh
# c to cd to ~/code
c() { cd ${CODE_DIRECTORY}/$1; }
# tab complete c against code
_c() { _files -W ${CODE_DIRECTORY} -/; }
compdef _c c
(Note: CODE_DIRECTORY is just an env var for ~/code)
I use this all the time and I use h to do the same for my home directory
https://github.com/gpspake/dotfiles/blob/master/zsh/gpspake/...
No need for an alias, a variable (I think that's what they're called) will do:
hello=~/Documents
Then: cd ~hello/world
Or omitting `cd` (requires `setopt auto_cd`): ~hello/world
And with `setopt cdable_vars`: hello/word
This also works with tab completion: hello/<TAB>With ZSH, you can use a named directory hash to create such 'aliases' to directories:
hash -d hello=~/Documents
~hello/world
The shortened names also show up in your PROMPT if it is using %~ to display cwd.fish abbreviations kinda do this, for example if you define your alias above as an abbrev and you type hello<space>, it replaces hello by ~/Documents in your command line. You still have to press backspace to remove the space you just inserted, but it's better than nothing.
Also, apparently you can add this to zsh with a plugin: https://github.com/momo-lab/zsh-abbrev-alias
fish-shell abbreviations are really cool, I do miss that in zsh, I'll probably give that plugin a go. It also makes it for other people easier to see what's going on when looking at the previous commands.
For example if I set the following alias:
It would be nice if I could then execute hello/world to take me to ~/Documents/world but it requires hardcoding.Guess I could play around with functions and arguments to solve this.