3 ms·
I wish I would chain things in the navigation alias. For example if I set the following alias: alias hello = '~/Docuemnts' It would be nice if I could th
by xmdx 6y ago
I wish I would chain things in the navigation alias.
For example if I set the following alias:
alias hello = '~/Docuemnts'
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.
- fratajcz 6y agofish 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 https://github.com/momo-lab/zsh-abbrev-alias
- lawry 6y agofish-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.
- gpspake 6y agoI 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/gpspake.plugin.zsh#L40 https://github.com/gpspake/dotfiles/blob/master/zsh/gpspake/...
- fphilipe 6y agoNo 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>
- wgetch 6y agoWith 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.
- smhmd 6y agoadd hash command in your $zshrc $ hash -d hello=$HOME/Documents $ cd ~hello/world && pwd /home/user/Documents/world