From 0f88a73fad999bcd2076a1cc586a4a7521226176 Mon Sep 17 00:00:00 2001 From: arlo Date: Thu, 19 Feb 2015 07:13:40 -0600 Subject: [PATCH] Adding autoloaded completion plugin for homeshick --- plugins/homeshick/_homeshick | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/homeshick/_homeshick diff --git a/plugins/homeshick/_homeshick b/plugins/homeshick/_homeshick new file mode 100644 index 00000000..e825303b --- /dev/null +++ b/plugins/homeshick/_homeshick @@ -0,0 +1,72 @@ +#compdef homeshick +#autoload + +_homeshick () { + local context state line curcontext="$curcontext" ret=1 + _arguments -n : \ + {-q,--quiet}'[Suppress status output]' \ + '(-s --skip)'{-f,--force}'[Overwrite files that already exist]' \ + '(-f --force)'{-s,--skip}'[Skip files that already exist]' \ + {-b,--batch}'[Batch-mode: Skip interactive prompt]' \ + {-h,--help}'[Help message]' \ + '1:commands:(cd clone generate list check refresh pull link track help)' \ + '*::arguments:->arguments' \ + && ret=0 + + case $state in + (arguments) + curcontext="${curcontext%:*:*}:homeshick-arguments-$words[1]:" + case $words[1] in + (cd) + _arguments \ + '1:castles:_homeshick_repo_folders' \ + && ret=0 + ;; + (check|refresh|pull) + _arguments \ + '*: :_homeshick_castles' \ + && ret=0 + ;; + (link) + _arguments \ + '*: :_homeshick_castles' \ + && ret=0 + ;; + (track) + _arguments \ + '1: :_homeshick_castles' \ + "*: :_path_files" \ + && ret=0 + ;; + (help) + _arguments \ + ':command:(cd clone generate list check refresh pull link track help)' \ + && ret=0 + ;; + esac + ;; + esac + + return ret +} + +_homeshick_repo_folders() { + _path_files -/W $HOME/.homesick/repos +} + +_homeshick_castles() +{ + local castles repos="$HOME/.homesick/repos" + castles=() + for repo in $(find $repos -mindepth 2 -maxdepth 2 -type d -name .git); do + castles+=($(_homeshick_basename "${repo%/.git}")) + done + _describe -t castles 'castle' castles && ret=0 +} + +_homeshick_basename() +{ + printf -- "${1##*/}" +} + +_homeshick "$@"