Change to Custom Directory Alias With Completions in Zsh (2021)

6 points by Aks


telemachus

Maybe I’m confused, but I think you can do this more easily. You don’t need a function to bookmark directories. Instead, you can use CDPATH or even better hash -d which gives you TAB-completion for free.

~ % hash -d dots=Documents/git-repos/dotfiles
~ % nvim ~dots/[TAB]
base16.yml              gitignore_global        pack-vim.sh*
bash_aliases            go-extras/              port.awk
bash_completion         go-kickstart.sh*        profile
bash_functions          home-setup.sh           README.md
bash_path               hushlogin               run-help-debian
bashrc                  inputrc                 run-help-macos
bin/                    IR_Black_Mine.terminal  stylua.toml
bin-linker.sh*          launchagents/           test-run-help.zsh
config/                 LICENSE.txt             TODO.md
dot_copier.sh*          macOS.sh*               vim/
dot_linker.sh*          mail-skel.sh            Vim-big.terminal
drive.icns              mpdconf                 Vim-small.terminal
etc_bashrc              nvim-kickstart.bash*    Vim.terminal
etc_profile             nvim-link.sh*           zshenv
foo/                    old-zshrc               zshrc
gitconfig               pack-nvim.sh*