diff options
author | Pavol Juhas <pavol.juhas@gmail.com> | 2020-08-27 00:44:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 09:44:25 +0200 |
commit | 8d08f1634a7b9782e3722ce770e8630f569afe3f (patch) | |
tree | e3af0b590afac65cd81e6bc416c70989e9fa0843 /plugins/scd/_scd | |
parent | cfb86cd08d3b24fd4b59d0d35b3af1f589c891fa (diff) | |
download | zsh-8d08f1634a7b9782e3722ce770e8630f569afe3f.tar.gz zsh-8d08f1634a7b9782e3722ce770e8630f569afe3f.tar.bz2 zsh-8d08f1634a7b9782e3722ce770e8630f569afe3f.zip |
scd: update to 1.4.0 (#9066)
Diffstat (limited to 'plugins/scd/_scd')
-rw-r--r-- | plugins/scd/_scd | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/plugins/scd/_scd b/plugins/scd/_scd new file mode 100644 index 000000000..39c7fa463 --- /dev/null +++ b/plugins/scd/_scd @@ -0,0 +1,60 @@ +#compdef scd +#description smart change directory + +local curcontext="$curcontext" state line expl ret=1 +typeset -A opt_args + +local -a indexopts myargs +indexopts=( --add -a --unindex ) + +myargs=( + # common options + "(--help -h)"{--help,-h}"[print help and exit]" + + # options for manipulating directory index + - index + "(--recursive -r)"{--recursive,-r}"[use recursive --add or --unindex]" + "($indexopts)"{--add,-a}"[add specified directories to the index]" + "($indexopts)--unindex[remove specified directories from the index]" + "*:directory:{ (( ${words[(I)-a|--add|--unindex]} )) && _path_files -/ }" + + # define new directory alias + - alias + "--alias=[create alias for this or given directory]:directory-alias:()" + '1:directory:{ (( words[(I)--alias*] )) && _path_files -/ }' + + # remove definition of directory alias + - unalias + "--unalias[remove definition of directory alias]" + "*::directory alias:->scd-alias-target" + + # act on the directory change + - scd + "(--all -A)"{--all,-A}"[include less likely and ignored paths]" + "--list[print matching directories and exit]" + "(--verbose -v)"{--verbose,-v}"[show directory ranking and full paths]" + "(--push -p)"{--push,-p}"[change directory with 'pushd']" + "1::directory alias:->scd-alias-target" + "*:patterns:()" +) + +_arguments -S -C $myargs && ret=0 + + +if [[ "$state" == scd-alias-target && -s ~/.scdalias.zsh ]]; then + local -a scdaliases + scdaliases=( ) + eval "$(setopt extendedglob + phome="(#b)(#s)${HOME}(/*)#(#e)" + builtin hash -dr + source ~/.scdalias.zsh && + for k v in ${(kv)nameddirs}; do + scdaliases+=( $k:${v/${~phome}/"~"${match[1]}} ) + done + complete_unalias=${+opt_args[unalias---unalias]} + if (( complete_unalias && ! ${+nameddirs[OLD]} )); then + scdaliases+=( 'OLD:all aliases to non-existent paths' ) + fi + typeset -p scdaliases )" + _describe -t scdaliases scdalias scdaliases +fi |