tags:

views:

29

answers:

1

Hi, How do you set up Z-shell so that typing cd - gives you a list of previously visited paths?

cd -1, -2, -3 etc then take you to the directories.

+1  A: 

If you use pushd instead of cd, then you can list directories with dirs and cd to old directory with popd. You can also set autopush option to get cd behave much like pushd -q. Here is an example:

setopt pushdsilent # Omit printing directory stack
setopt autopush    # Make cd push directories onto stack
setopt pushdminus  # Invert meanings of +N and -N arguments to pushd
mkdir -p 1/2/3/4
cd 1
cd 2
cd 3
cd 4
popd     # Go to previous directory (3) and remove it from directory stack
pushd -  # Go to previous directory (4)
pushd -2 # Go 2 directories back the directory stack (2)

Note that pushd does not remove anything from the directory stack, it only rotates it. See man zshbuiltins for more details.

ZyX