Z – quickly cd to 'frecent' directories
New, alternative directory-changing behavior in ZSH-z
RUP?
A Beautiful Tihai in Rupak Taal
Please Subscribe
More on reddit.comVideos
In the z readme, after line 50, it says:
Installation:
Put something like this in your $HOME/.bashrc or $HOME/.zshrc:
. /path/to/z.shcd around for a while to build up the db.
You need to download the z.sh file to a directory of your choosing, then tell your .bashrc where it is, so your terminal can find it. (The same applies for z-shell, which is just another shell system.) Then, after you use bash for a while, z will know your favorite locations.
You can download and add to *rc files using command line as so
# Download to latest to home dir
wget "https://raw.githubusercontent.com/rupa/z/master/z.sh" -O "~/z.sh"
# Add to .bashrc
echo "source /path/to/z.sh" >> ~/.bashrc
# Add to .zshrc
echo "source /path/to/z.sh" >> ~/.zshrc
ZSH-z is a command line tool that allows you to jump quickly to directories that you have visited frequently in the past, or recently -- but most often a combination of the two (a concept known as "frecency"). ZSH-z is a native ZSH port of rupa/z, but it uses native ZSH features to avoid having to invoke external programs such as awk, sed, sort, date, and the like.
A new setting, ZSHZ_UNCOMMON=1, addresses a common complaint about rupa/z and ZSH-z that involves "common prefixes."
If you type z code and the best matches, in increasing order, are
/home/me/code/foo /home/me/code/bar /home/me/code/bat
ZSH-z will see that all possible matches share a common prefix and will send you to that directory -- /home/me/code -- which is often a desirable result. But if the possible matches are
/home/me/.vscode/foo /home/me/code/foo /home/me/code/bar /home/me/code/bat
then there is no common prefix. In this case, z code will simply send you to the highest-ranking match, /home/me/code/bat.
You may enable an alternate, experimental behavior by setting ZSHZ_UNCOMMON=1. If you do that, ZSH-z will not jump to a common prefix, even if one exists. Instead, it chooses the highest-ranking match -- but it drops any subdirectories that do not include the search term. So if you type z bat and /home/me/code/bat is the best match, that is exactly where you will end up. If, however, you had typed z code and the best match was also /home/me/code/bat, you would have ended up in /home/me/code (because code was what you had searched for). This feature is still in development, and feedback is welcome.
https://github.com/agkozak/zsh-z