From 49458b872d1bab1aa8338e319f27c9b3705c9fd7 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 29 Oct 2021 18:21:13 +0200 Subject: docs(dirhistory): document OPT key alternative for macOS and fix style Fixes #10350 --- plugins/dirhistory/README.md | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'plugins/dirhistory') diff --git a/plugins/dirhistory/README.md b/plugins/dirhistory/README.md index 602fc8284..ede9b5410 100644 --- a/plugins/dirhistory/README.md +++ b/plugins/dirhistory/README.md @@ -12,19 +12,27 @@ plugins=(... dirhistory) | Shortcut | Description | |-----------------------------------|-----------------------------------------------------------| -| alt + left | Go to previous directory | -| alt + right | Undo alt + left | -| alt + up | Move into the parent directory | -| alt + down | Move into the first child directory by alphabetical order | +| 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 | -NOTE: some terminals might override the ALT+Arrows key bindings (Windows Terminal, for example). -If these don't work check your terminal settings and change them to a different keyboard shortcut. +**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 current-working-directories using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. MAC users may alternately use OPT-LEFT and OPT-RIGHT. +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.** -Also, navigate directory **hierarchy** using ALT-UP and ALT-DOWN. (mac keybindings not yet implemented). ALT-UP moves to higher hierarchy (shortcut for 'cd ..'). ALT-DOWN moves into the first directory found in alphabetical order (useful to navigate long empty directories e.g. java packages) +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: @@ -35,8 +43,20 @@ cd share cd doc ``` -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. +the directory stack (`dirs -v`) would look like this: + +```console +$ dirs -v +0 /usr/share/doc +1 /usr/share +2 /usr +3 ~ +``` -After that, ALT-DOWN will probably go to /usr/bin (depends on your /usr structure), ALT-UP will return to /usr, then ALT-UP will get you to / +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. -**Currently the max history size is 30**. The navigation should work for xterm, PuTTY xterm mode, GNU screen, and on MAC with alternate keys as mentioned above. +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 (`/`). -- cgit v1.2.3-70-g09d2 From 7f494944e6e8047b49fdbd42977b4eb4670381fe Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 29 Oct 2021 18:22:35 +0200 Subject: fix(dirhistory): fix ALT+Up/Down key bindings for Terminal.app --- plugins/dirhistory/dirhistory.plugin.zsh | 76 ++++++++++++++------------------ 1 file changed, 32 insertions(+), 44 deletions(-) (limited to 'plugins/dirhistory') diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index cbac84600..d949064d8 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -121,35 +121,24 @@ function dirhistory_zle_dirhistory_future() { } zle -N dirhistory_zle_dirhistory_back -# xterm in normal mode -bindkey "\e[3D" dirhistory_zle_dirhistory_back -bindkey "\e[1;3D" dirhistory_zle_dirhistory_back -# Terminal.app -if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then - bindkey "^[b" dirhistory_zle_dirhistory_back -fi -# iTerm2 -if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[^[[D" dirhistory_zle_dirhistory_back -fi -# Putty: -bindkey "\e\e[D" dirhistory_zle_dirhistory_back -# GNU screen: -bindkey "\eO3D" dirhistory_zle_dirhistory_back +bindkey "\e[3D" dirhistory_zle_dirhistory_back # xterm in normal mode +bindkey "\e[1;3D" dirhistory_zle_dirhistory_back # xterm in normal mode +bindkey "\e\e[D" dirhistory_zle_dirhistory_back # Putty +bindkey "\eO3D" dirhistory_zle_dirhistory_back # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2 +Apple_Terminal) bindkey "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app +esac zle -N dirhistory_zle_dirhistory_future -bindkey "\e[3C" dirhistory_zle_dirhistory_future -bindkey "\e[1;3C" dirhistory_zle_dirhistory_future -# Terminal.app -if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then - bindkey "^[f" dirhistory_zle_dirhistory_future -fi -# iTerm2 -if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[^[[C" dirhistory_zle_dirhistory_future -fi -bindkey "\e\e[C" dirhistory_zle_dirhistory_future -bindkey "\eO3C" dirhistory_zle_dirhistory_future +bindkey "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode +bindkey "\e[1;3C" dirhistory_zle_dirhistory_future # xterm in normal mode +bindkey "\e\e[C" dirhistory_zle_dirhistory_future # Putty +bindkey "\eO3C" dirhistory_zle_dirhistory_future # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2 +Apple_Terminal) bindkey "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app +esac # @@ -181,22 +170,21 @@ function dirhistory_zle_dirhistory_down() { } zle -N dirhistory_zle_dirhistory_up -# xterm in normal mode -bindkey "\e[3A" dirhistory_zle_dirhistory_up -bindkey "\e[1;3A" dirhistory_zle_dirhistory_up -if [[ "$TERM_PROGRAM" == "Apple_Terminal" || "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[[A" dirhistory_zle_dirhistory_up -fi -# Putty: -bindkey "\e\e[A" dirhistory_zle_dirhistory_up -# GNU screen: -bindkey "\eO3A" dirhistory_zle_dirhistory_up +bindkey "\e[3A" dirhistory_zle_dirhistory_up # xterm in normal mode +bindkey "\e[1;3A" dirhistory_zle_dirhistory_up # xterm in normal mode +bindkey "\e\e[A" dirhistory_zle_dirhistory_up # Putty +bindkey "\eO3A" dirhistory_zle_dirhistory_up # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 +Apple_Terminal) bindkey "^[OA" dirhistory_zle_dirhistory_up ;; # Terminal.app +esac zle -N dirhistory_zle_dirhistory_down -bindkey "\e[3B" dirhistory_zle_dirhistory_down -bindkey "\e[1;3B" dirhistory_zle_dirhistory_down -if [[ "$TERM_PROGRAM" == "Apple_Terminal" || "$TERM_PROGRAM" == "iTerm.app" ]]; then - bindkey "^[[B" dirhistory_zle_dirhistory_down -fi -bindkey "\e\e[B" dirhistory_zle_dirhistory_down -bindkey "\eO3B" dirhistory_zle_dirhistory_down +bindkey "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode +bindkey "\e[1;3B" dirhistory_zle_dirhistory_down # xterm in normal mode +bindkey "\e\e[B" dirhistory_zle_dirhistory_down # Putty +bindkey "\eO3B" dirhistory_zle_dirhistory_down # GNU screen +case "$TERM_PROGRAM" in +iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 +Apple_Terminal) bindkey "^[OB" dirhistory_zle_dirhistory_down ;; # Terminal.app +esac -- cgit v1.2.3-70-g09d2 From 79cf4b3ceb9bf981ce05adc1db3f01aa551efce8 Mon Sep 17 00:00:00 2001 From: Michael Peick Date: Sun, 10 Nov 2019 15:32:41 +0100 Subject: feat(dirhistory): support urxvt terminal key binding (#8370) Closes #8370 --- plugins/dirhistory/dirhistory.plugin.zsh | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'plugins/dirhistory') diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index d949064d8..26ef07494 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -1,7 +1,7 @@ -## -# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories +## +# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories # that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. -# +# # Navigate directory hierarchy using ALT-UP and ALT-DOWN. # ALT-UP moves to higher hierarchy (cd ..) # ALT-DOWN moves into the first directory found in alphabetical order @@ -14,8 +14,8 @@ export dirhistory_future export DIRHISTORY_SIZE=30 -# Pop the last element of dirhistory_past. -# Pass the name of the variable to return the result in. +# 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, # otherwise returns empty string. function pop_past() { @@ -32,7 +32,7 @@ function pop_future() { fi } -# Push a new element onto the end of dirhistory_past. If the size of the array +# Push a new element onto the end of dirhistory_past. If the size of the array # is >= DIRHISTORY_SIZE, the array is shifted function push_past() { if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then @@ -76,7 +76,7 @@ function dirhistory_back() { local d="" # Last element in dirhistory_past is the cwd. - pop_past cw + pop_past cw if [[ "" == "$cw" ]]; then # Someone overwrote our variable. Recover it. dirhistory_past=($PWD) @@ -129,6 +129,9 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2 Apple_Terminal) bindkey "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app esac +if (( ${+terminfo[kcub1]} )); then + bindkey "^[${terminfo[kcub1]}" dirhistory_zle_dirhistory_back # urxvt +fi zle -N dirhistory_zle_dirhistory_future bindkey "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode @@ -139,11 +142,14 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2 Apple_Terminal) bindkey "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app esac +if (( ${+terminfo[kcuf1]} )); then + bindkey "^[${terminfo[kcuf1]}" dirhistory_zle_dirhistory_future # urxvt +fi -# +# # HIERARCHY Implemented in this section, in case someone wants to split it to another plugin if it clashes bindings -# +# # Move up in hierarchy function dirhistory_up() { @@ -178,6 +184,9 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 Apple_Terminal) bindkey "^[OA" dirhistory_zle_dirhistory_up ;; # Terminal.app esac +if (( ${+terminfo[kcuu1]} )); then + bindkey "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt +fi zle -N dirhistory_zle_dirhistory_down bindkey "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode @@ -188,3 +197,6 @@ case "$TERM_PROGRAM" in iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 Apple_Terminal) bindkey "^[OB" dirhistory_zle_dirhistory_down ;; # Terminal.app esac +if (( ${+terminfo[kcud1]} )); then + bindkey "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt +fi -- cgit v1.2.3-70-g09d2