Videos
Factsheet
I've used z.sh both in bash and in ZSH for years now to jump quickly from directory to directory. That script relies heavily on awk, and it struck me that the same job could be done in ZSH without awk -- or date, sort, or sed, for that matter.
I'd like to introduce ZSH-z, a native ZSH port of z.sh. It's quite a bit faster than its original, as it avoids unnecessary subshells, and the only external commands it still uses are mv and rm. The speed increase can be felt particularly on Windows (MSYS2/Cygwin/WSL), which has problems with forking.
I've also introduced little fixes, and one new feature which is now on by default: completion menus are populated according to how often you go to directories and how recently you've been to them ("frecency"), whereas in the original the menu is simply sorted alphabetically. The original behavior is still there if you set ZSHZ_COMPLETION=legacy.
https://github.com/agkozak/zsh-z
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
I got it!,
First:
vim ~/.zshrc
and
plugins=(
git
z
)
exit with :x!
And run
source ~/.zshrc
Another possibility,unalias -a is put below source /path/to/z.sh or source /path/to/oh-my-zsh.sh, because z is an alias for _z
$ type z
z is an alias for _z 2>&1
so, remove unalias -a (or comment this line )
or put it above source /path/to/oh-my-zsh.sh(or source /path/to/z.sh). eg:
unalias -a
source $ZSH/oh-my-zsh.sh
or add source $ZSH/oh-my-zsh.sh at the end of .zshrc file.
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