summaryrefslogtreecommitdiff
path: root/plugins/dirhistory
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2026-01-04 22:47:54 -0800
committerTuowen Zhao <ztuowen@gmail.com>2026-01-04 22:47:54 -0800
commit2aa4cb7a52b28722816ecfd55f3b06293332c55c (patch)
treef02a9f3d59d109c70caf932a24e43368994e0e8c /plugins/dirhistory
parent7e951c254e779ff0620537cf43ca69dd878387b4 (diff)
parentd23d3ea69fdb839088e6e5589557cce77b34aaf8 (diff)
downloadzsh-master.tar.gz
zsh-master.tar.bz2
zsh-master.zip
Merge remote-tracking branch 'github/master'HEADmaster
Diffstat (limited to 'plugins/dirhistory')
-rw-r--r--plugins/dirhistory/README.md43
-rw-r--r--plugins/dirhistory/dirhistory.plugin.zsh17
2 files changed, 57 insertions, 3 deletions
diff --git a/plugins/dirhistory/README.md b/plugins/dirhistory/README.md
index ede9b5410..66e3e0469 100644
--- a/plugins/dirhistory/README.md
+++ b/plugins/dirhistory/README.md
@@ -60,3 +60,46 @@ to `/usr` again.
After that, <kbd>Alt</kbd> + <kbd>Down</kbd> will probably go to `/usr/bin` if `bin` is the first directory in alphabetical
order (depends on your `/usr` folder structure). <kbd>Alt</kbd> + <kbd>Up</kbd> 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:
+
+```shell
+cd ~
+cd /usr
+cd share
+cd doc
+
+# <Alt + Left>
+# <Alt + Left>
+```
+
+The directory stack would look like this:
+
+```sh
+➜ /usr typeset -pm dirhistory_\*
+typeset -ax dirhistory_past=( /home/user /usr )
+typeset -ax dirhistory_future=( /usr/share/doc /usr/share )
+```
+
+This means that pressing <kbd>Alt</kbd> + <kbd>Right</kbd>, 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 <kbd>Alt</kbd> + <kbd>Right</kbd>:
+
+```sh
+➜ /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:
+
+```sh
+➜ /u/bin typeset -pm dirhistory_\*
+typeset -ax dirhistory_past=( /home/user /usr /usr/bin )
+typeset -ax dirhistory_future=( /usr/share/doc /usr/share )
+```
diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh
index 8d67c6188..706bb6fb2 100644
--- a/plugins/dirhistory/dirhistory.plugin.zsh
+++ b/plugins/dirhistory/dirhistory.plugin.zsh
@@ -11,9 +11,10 @@ dirhistory_past=($PWD)
dirhistory_future=()
export dirhistory_past
export dirhistory_future
-
export DIRHISTORY_SIZE=30
+alias cde='dirhistory_cd'
+
# Pop the last element of dirhistory_past.
# Pass the name of the variable to return the result in.
# Returns the element if the array was not empty,
@@ -136,7 +137,11 @@ for keymap in emacs vicmd viins; do
case "$TERM_PROGRAM" in
Apple_Terminal) bindkey -M $keymap "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app
- iTerm.app) bindkey -M $keymap "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2
+ ghostty) bindkey -M $keymap "^[b" dirhistory_zle_dirhistory_back ;; # ghostty
+ iTerm.app)
+ bindkey -M $keymap "^[^[[D" dirhistory_zle_dirhistory_back
+ bindkey -M $keymap "^[b" dirhistory_zle_dirhistory_back
+ ;;
esac
if (( ${+terminfo[kcub1]} )); then
@@ -151,7 +156,11 @@ for keymap in emacs vicmd viins; do
case "$TERM_PROGRAM" in
Apple_Terminal) bindkey -M $keymap "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app
- iTerm.app) bindkey -M $keymap "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2
+ ghostty) bindkey -M $keymap "^[f" dirhistory_zle_dirhistory_future ;; # ghostty
+ iTerm.app)
+ bindkey -M $keymap "^[^[[C" dirhistory_zle_dirhistory_future
+ bindkey -M $keymap "^[f" dirhistory_zle_dirhistory_future
+ ;;
esac
if (( ${+terminfo[kcuf1]} )); then
@@ -200,6 +209,7 @@ for keymap in emacs vicmd viins; do
case "$TERM_PROGRAM" in
Apple_Terminal) bindkey -M $keymap "^[[A" dirhistory_zle_dirhistory_up ;; # Terminal.app
iTerm.app) bindkey -M $keymap "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2
+ ghostty) bindkey -M $keymap "^[[1;3A" dirhistory_zle_dirhistory_up ;; # ghostty
esac
if (( ${+terminfo[kcuu1]} )); then
@@ -215,6 +225,7 @@ for keymap in emacs vicmd viins; do
case "$TERM_PROGRAM" in
Apple_Terminal) bindkey -M $keymap "^[[B" dirhistory_zle_dirhistory_down ;; # Terminal.app
iTerm.app) bindkey -M $keymap "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2
+ ghostty) bindkey -M $keymap "^[[1;3B" dirhistory_zle_dirhistory_down ;; # ghostty
esac
if (( ${+terminfo[kcud1]} )); then