|
||
---|---|---|
.. | ||
dirhistory.plugin.zsh | ||
README.md |
Dirhistory plugin
This plugin adds keyboard shortcuts for navigating directory history and hierarchy.
To use it, add dirhistory
to the plugins array in your zshrc file:
plugins=(... dirhistory)
Keyboard Shortcuts
Shortcut | Description |
---|---|
Alt + Left | Go to previous directory |
Alt + Right | Go to next directory |
Alt + Up | Move into the parent directory |
Alt + Down | Move into the first child directory by alphabetical order |
For macOS: use the Option key (⌥) instead of Alt.
NOTE: some terminals might override the Alt + Arrows key bindings (e.g. Windows Terminal). If these don't work check your terminal settings and change them to a different keyboard shortcut.
Usage
This plugin allows you to navigate the history of previous working directories using Alt + Left and Alt + Right. Alt + Left moves to past directories, and Alt + Right goes back to recent directories.
NOTE: the maximum directory history size is 30.
You can also navigate directory hierarchies using Alt + Up and Alt + Down. Alt + Up moves to the parent directory, while Alt + Down moves into the first child directory found in alphabetical order (useful to navigate long empty directories, e.g. Java packages).
For example, if the shell was started, and the following commands were entered:
cd ~
cd /usr
cd share
cd doc
the directory stack (dirs -v
) would look like this:
$ dirs -v
0 /usr/share/doc
1 /usr/share
2 /usr
3 ~
then entering Alt + Left at the prompt would change directory from /usr/share/doc
to /usr/share
,
then if pressed again to /usr
, then ~
. If Alt + Right were pressed the directory would be changed
to /usr
again.
After that, Alt + Down will probably go to /usr/bin
if bin
is the first directory in alphabetical
order (depends on your /usr
folder structure). Alt + Up will return to /usr
, and once more will get
you to the root folder (/
).
cde
This plugin also provides a cde
alias that allows you to change to a directory without clearing the next directory stack.
This changes the default behavior of dirhistory
, which is to clear the next directory stack when changing directories.
For example, if the shell was started, and the following commands were entered:
cd ~
cd /usr
cd share
cd doc
# <Alt + Left>
# <Alt + Left>
The directory stack would look like this:
➜ /usr typeset -pm dirhistory_\*
typeset -ax dirhistory_past=( /home/user /usr )
typeset -ax dirhistory_future=( /usr/share/doc /usr/share )
This means that pressing Alt + Right, you'd go to /usr/share
and /usr/share/doc
(the "future" directories).
If you run cd /usr/bin
, the "future" directories will be removed, and you won't be able to access them with Alt + Right:
➜ /u/bin typeset -pm dirhistory_\*
typeset -ax dirhistory_past=( /home/user /usr )
typeset -ax dirhistory_future=( /usr/bin )
If you instead run cde /usr/bin
, the "future" directories will be preserved:
➜ /u/bin typeset -pm dirhistory_\*
typeset -ax dirhistory_past=( /home/user /usr /usr/bin )
typeset -ax dirhistory_future=( /usr/share/doc /usr/share )