d02d008579e8b1e17cb86f2a03286f823a9fb773

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

Add directory hierarchy navigation to dirhistory (#6756)

* New Feature:
  Navigate directory hierarchy using ALT-UP and ALT-DOWN. (mac keybindings not yet implemented)
  ALT-UP moves to higher hierarchy (cd ..)
  ALT-DOWN moves into the first directory found in alphabetical order

Diff

 1diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh
 2index 283dace2923094c6b05446c053abf378adb1327e..239915e4821fec0264ef8bffb256f1c87c77ae0b 100644
 3--- a/plugins/dirhistory/dirhistory.plugin.zsh
 4+++ b/plugins/dirhistory/dirhistory.plugin.zsh
 5@@ -2,6 +2,10 @@
 6 #   Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories 
 7 #   that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT.
 8 # 
 9+#   Navigate directory hierarchy using ALT-UP and ALT-DOWN. (mac keybindings not yet implemented)
10+#   ALT-UP moves to higher hierarchy (cd ..)
11+#   ALT-DOWN moves into the first directory found in alphabetical order
12+#
13 
14 dirhistory_past=($PWD)
15 dirhistory_future=()
16@@ -138,3 +142,49 @@ bindkey "\e\e[C" dirhistory_zle_dirhistory_future
17 bindkey "\eO3C" dirhistory_zle_dirhistory_future
18 
19 
20+# 
21+# HIERARCHY Implemented in this section, in case someone wants to split it to another plugin if it clashes bindings
22+# 
23+
24+# Move up in hierarchy
25+function dirhistory_up() {
26+  cd .. || return 1
27+}
28+
29+# Move down in hierarchy
30+function dirhistory_down() {
31+  cd "$(find . -mindepth 1 -maxdepth 1 -type d | sort -n | head -n 1)" || return 1
32+}
33+
34+
35+# Bind keys to hierarchy navigation
36+function dirhistory_zle_dirhistory_up() {
37+  zle kill-buffer   # Erase current line in buffer
38+  dirhistory_up
39+  zle accept-line
40+}
41+
42+function dirhistory_zle_dirhistory_down() {
43+  zle kill-buffer   # Erase current line in buffer
44+  dirhistory_down
45+  zle accept-line
46+}
47+
48+zle -N dirhistory_zle_dirhistory_up
49+# xterm in normal mode
50+bindkey "\e[3A" dirhistory_zle_dirhistory_up
51+bindkey "\e[1;3A" dirhistory_zle_dirhistory_up
52+# Mac teminal (alt+up)
53+    #bindkey "^[?" dirhistory_zle_dirhistory_up #dont know it
54+# Putty:
55+bindkey "\e\e[A" dirhistory_zle_dirhistory_up
56+# GNU screen:
57+bindkey "\eO3A" dirhistory_zle_dirhistory_up
58+
59+zle -N dirhistory_zle_dirhistory_down
60+bindkey "\e[3B" dirhistory_zle_dirhistory_down
61+bindkey "\e[1;3B" dirhistory_zle_dirhistory_down
62+# Mac teminal (alt+down)
63+    #bindkey "^[?" dirhistory_zle_dirhistory_down #dont know it
64+bindkey "\e\e[B" dirhistory_zle_dirhistory_down
65+bindkey "\eO3B" dirhistory_zle_dirhistory_down