diff --git a/modules/directory/README.md b/modules/directory/README.md index 6572bb7..4ba8fbf 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 0000000..21ce4d9 --- /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 3be411b..debb045 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