diff --git a/modules/directory/README.md b/modules/directory/README.md index 6572bb72..4ba8fbfb 100644 --- a/modules/directory/README.md +++ b/modules/directory/README.md @@ -22,7 +22,11 @@ Aliases ------- - `d` prints the contents of the directory stack. - - `1 ... 9` changes the directory to the **n** previous one. + +Functions +--------- + + - `command_not_found_handler` changes the directory to the **n** previous one. Authors ------- diff --git a/modules/directory/functions/command_not_found_handler b/modules/directory/functions/command_not_found_handler new file mode 100644 index 00000000..21ce4d97 --- /dev/null +++ b/modules/directory/functions/command_not_found_handler @@ -0,0 +1,13 @@ +# +# Changes the directory to the n previous one. +# +# Authors: +# Sorin Ionescu +# + +if [[ "$1" == [[:digit:]]## ]]; then + builtin cd "+$1" +else + return 127 +fi + diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh index 3be411b5..debb0459 100644 --- a/modules/directory/init.zsh +++ b/modules/directory/init.zsh @@ -27,5 +27,4 @@ unsetopt CLOBBER # Do not overwrite existing files with > and >>. # alias d='dirs -v' -for index ({1..9}) alias "$index"="cd +${index}"; unset index