7bb7ce62d3a78859aa15151ecc46df5adc9cf049

Author
Francisco Zuviría <FranciscodeZuviria@fusap.com.ar>
Committer
Francisco Zuviría <FranciscodeZuviria@fusap.com.ar>
Date

Message

 On branch fzuviria.plugin.dirhistory.new-feature.navigate-history
 Changes to be committed:
	modified:   dirhistory/dirhistory.plugin.zsh

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 8138872bc4d2f168e115e2808ab96e5aac2d2db0..05839e35a6652627c48ea3bf13f14495be0d1d5f 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@@ -134,3 +138,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 ..
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`"
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