Update 30.01.2022
This commit is contained in:
@@ -12,19 +12,27 @@ plugins=(... dirhistory)
|
||||
|
||||
| Shortcut | Description |
|
||||
|-----------------------------------|-----------------------------------------------------------|
|
||||
| <kbd>alt</kbd> + <kbd>left</kbd> | Go to previous directory |
|
||||
| <kbd>alt</kbd> + <kbd>right</kbd> | Undo <kbd>alt</kbd> + <kbd>left</kbd> |
|
||||
| <kbd>alt</kbd> + <kbd>up</kbd> | Move into the parent directory |
|
||||
| <kbd>alt</kbd> + <kbd>down</kbd> | Move into the first child directory by alphabetical order |
|
||||
| <kbd>Alt</kbd> + <kbd>Left</kbd> | Go to previous directory |
|
||||
| <kbd>Alt</kbd> + <kbd>Right</kbd> | Go to next directory |
|
||||
| <kbd>Alt</kbd> + <kbd>Up</kbd> | Move into the parent directory |
|
||||
| <kbd>Alt</kbd> + <kbd>Down</kbd> | 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 (<kbd>⌥</kbd>) instead of <kbd>Alt</kbd>**.
|
||||
|
||||
> NOTE: some terminals might override the <kbd>Alt</kbd> + 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 <kbd>Alt</kbd> + <kbd>Left</kbd>
|
||||
and <kbd>Alt</kbd> + <kbd>Right</kbd>. <kbd>Alt</kbd> + <kbd>Left</kbd> moves to past directories, and
|
||||
<kbd>Alt</kbd> + <kbd>Right</kbd> goes back to recent directories.
|
||||
|
||||
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)
|
||||
**NOTE: the maximum directory history size is 30.**
|
||||
|
||||
You can also navigate **directory hierarchies** using <kbd>Alt</kbd> + <kbd>Up</kbd> and <kbd>Alt</kbd> + <kbd>Down</kbd>.
|
||||
<kbd>Alt</kbd> + <kbd>Up</kbd> moves to the parent directory, while <kbd>Alt</kbd> + <kbd>Down</kbd> 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:
|
||||
|
||||
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 /
|
||||
```console
|
||||
$ dirs -v
|
||||
0 /usr/share/doc
|
||||
1 /usr/share
|
||||
2 /usr
|
||||
3 ~
|
||||
```
|
||||
|
||||
**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.
|
||||
then entering <kbd>Alt</kbd> + <kbd>Left</kbd> at the prompt would change directory from `/usr/share/doc` to `/usr/share`,
|
||||
then if pressed again to `/usr`, then `~`. If <kbd>Alt</kbd> + <kbd>Right</kbd> were pressed the directory would be changed
|
||||
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 (`/`).
|
||||
|
||||
@@ -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,25 +14,25 @@ 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() {
|
||||
eval "$1='$dirhistory_past[$#dirhistory_past]'"
|
||||
typeset -g $1="${dirhistory_past[$#dirhistory_past]}"
|
||||
if [[ $#dirhistory_past -gt 0 ]]; then
|
||||
dirhistory_past[$#dirhistory_past]=()
|
||||
fi
|
||||
}
|
||||
|
||||
function pop_future() {
|
||||
eval "$1='$dirhistory_future[$#dirhistory_future]'"
|
||||
typeset -g $1="${dirhistory_future[$#dirhistory_future]}"
|
||||
if [[ $#dirhistory_future -gt 0 ]]; then
|
||||
dirhistory_future[$#dirhistory_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)
|
||||
@@ -121,40 +121,43 @@ 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
|
||||
|
||||
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
|
||||
|
||||
for keymap in emacs vicmd viins; do
|
||||
# dirhistory_back
|
||||
bindkey -M $keymap "\e[3D" dirhistory_zle_dirhistory_back # xterm in normal mode
|
||||
bindkey -M $keymap "\e[1;3D" dirhistory_zle_dirhistory_back # xterm in normal mode
|
||||
bindkey -M $keymap "\e\e[D" dirhistory_zle_dirhistory_back # Putty
|
||||
bindkey -M $keymap "\eO3D" dirhistory_zle_dirhistory_back # GNU screen
|
||||
|
||||
#
|
||||
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
|
||||
esac
|
||||
|
||||
if (( ${+terminfo[kcub1]} )); then
|
||||
bindkey -M $keymap "^[${terminfo[kcub1]}" dirhistory_zle_dirhistory_back # urxvt
|
||||
fi
|
||||
|
||||
# dirhistory_future
|
||||
bindkey -M $keymap "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode
|
||||
bindkey -M $keymap "\e[1;3C" dirhistory_zle_dirhistory_future # xterm in normal mode
|
||||
bindkey -M $keymap "\e\e[C" dirhistory_zle_dirhistory_future # Putty
|
||||
bindkey -M $keymap "\eO3C" dirhistory_zle_dirhistory_future # GNU screen
|
||||
|
||||
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
|
||||
esac
|
||||
|
||||
if (( ${+terminfo[kcuf1]} )); then
|
||||
bindkey -M $keymap "^[${terminfo[kcuf1]}" dirhistory_zle_dirhistory_future # urxvt
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# 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() {
|
||||
@@ -181,22 +184,38 @@ 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
|
||||
|
||||
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
|
||||
|
||||
for keymap in emacs vicmd viins; do
|
||||
# dirhistory_up
|
||||
bindkey -M $keymap "\e[3A" dirhistory_zle_dirhistory_up # xterm in normal mode
|
||||
bindkey -M $keymap "\e[1;3A" dirhistory_zle_dirhistory_up # xterm in normal mode
|
||||
bindkey -M $keymap "\e\e[A" dirhistory_zle_dirhistory_up # Putty
|
||||
bindkey -M $keymap "\eO3A" dirhistory_zle_dirhistory_up # GNU screen
|
||||
|
||||
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
|
||||
esac
|
||||
|
||||
if (( ${+terminfo[kcuu1]} )); then
|
||||
bindkey -M $keymap "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt
|
||||
fi
|
||||
|
||||
# dirhistory_down
|
||||
bindkey -M $keymap "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode
|
||||
bindkey -M $keymap "\e[1;3B" dirhistory_zle_dirhistory_down # xterm in normal mode
|
||||
bindkey -M $keymap "\e\e[B" dirhistory_zle_dirhistory_down # Putty
|
||||
bindkey -M $keymap "\eO3B" dirhistory_zle_dirhistory_down # GNU screen
|
||||
|
||||
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
|
||||
esac
|
||||
|
||||
if (( ${+terminfo[kcud1]} )); then
|
||||
bindkey -M $keymap "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt
|
||||
fi
|
||||
done
|
||||
|
||||
unset keymap
|
||||
|
||||
Reference in New Issue
Block a user