How do I install "z" script?

In the z readme after line 48, it says:

Installation:

Put something like this in your $HOME/.bashrc or $HOME/.zshrc:

. /path/to/z.sh

cd 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 . /path/to/z.sh >> ~/.bashrc
# Add to .zshrc
echo . /path/to/z.sh >> ~/.zshrc

From here

  • Download wget https://raw.githubusercontent.com/rupa/z/master/z.sh.

  • Install printf "\n\n#initialize Z (https://github.com/rupa/z) \n. ~/z.sh \n\n" >> .bashrc. This command appends . ~/z.sh to your .bashrc file, which in turn tells it to run Z upon start-up.

  • Reload shell source ~/.bashrc.

To test how Z works, browse to these directories:

cd /etc/systemd/system
cd /usr/share/nano
cd /etc/kernel/postinst.d
cd ~

Now, from your terminal, type in z sys and push the tab button, then enter. Next, type z nano and hit the tab button, then enter again. You will see in both cases that Z automatically knew to cd into the first and second directories where we initially browsed.

Using Z with Zsh

  • Run printf "\n\n#initialize Z (https://github.com/rupa/z) \n. ~/z.sh \n\n" >> .zshrc. This command appends . ~/z.sh to .zshrc file, which tells it to run Z on start-up.
  • Reload shell source ~/.zshrc.

Using Z with Zsh + Oh My Zsh

Just add z to the plugins list in ~/.zshrc

plugins=(
 git
 z
)

Download the z script to your home directory:

wget https://raw.githubusercontent.com/rupa/z/master/z.sh -O ~/.z

Then:

source ~/.zshrc