1#compdef vcsh 2 3function __vcsh_repositories () { 4 local expl 5 local -a repos 6 repos=( ${(f)"$(command vcsh list)"} ) 7 _describe -t repos 'repositories' repos 8} 9 10function __vcsh_not_implemented_yet () { 11 _message "Subcommand completion '${1#*-}': not implemented yet" 12} 13 14function _vcsh-clone () { 15 __vcsh_not_implemented_yet "$0" #TODO 16} 17 18function _vcsh-delete () { 19 (( CURRENT == 2 )) && __vcsh_repositories 20} 21 22function _vcsh-enter () { 23 (( CURRENT == 2 )) && __vcsh_repositories 24} 25 26function _vcsh-help () { 27 _nothing 28} 29 30function _vcsh-init () { 31 _nothing 32} 33 34function _vcsh-list () { 35 _nothing 36} 37 38function _vcsh-list-tracked () { 39 _nothing 40} 41 42function _vcsh-list-tracked-by () { 43 (( CURRENT == 2 )) && __vcsh_repositories 44} 45 46function _vcsh-pull () { 47 _nothing 48} 49 50function _vcsh-push () { 51 _nothing 52} 53 54function _vcsh-rename () { 55 (( CURRENT == 2 )) && __vcsh_repositories 56 (( CURRENT == 3 )) && _message "new repository name" 57 (( CURRENT > 3 )) && _nothing 58} 59 60function _vcsh-run () { 61 (( CURRENT == 2 )) && __vcsh_repositories 62 if (( CURRENT >= 3 )); then 63 words=( "${(@)words[3,-1]}" ) 64 (( CURRENT -= 2 )) 65 _complete 66 fi 67} 68 69function _vcsh-upgrade () { 70 (( CURRENT == 2 )) && __vcsh_repositories 71} 72 73function _vcsh-version () { 74 _nothing 75} 76 77function _vcsh-which () { 78 _files 79} 80 81function _vcsh-write-gitignore () { 82 (( CURRENT == 2 )) && __vcsh_repositories 83} 84 85function _vcsh () { 86 local curcontext="${curcontext}" 87 local state vcshcommand 88 local -a args subcommands 89 90 subcommands=( 91 "clone:clone an existing repository" 92 "delete:delete an existing repository" 93 "enter:enter repository; spawn new <\$SHELL>" 94 "help:display help" 95 "init:initialize an empty repository" 96 "list:list all local vcsh repositories" 97 "list-tracked:list all files tracked by vcsh" 98 "list-tracked-by:list files tracked by a repository" 99 "pull:pull from all vcsh remotes" 100 "rename:rename a repository" 101 "run:run command with <\$GIT_DIR> and <\$GIT_WORK_TREE> set" 102 "upgrade:upgrade repository to currently recommended settings" 103 "version:print version information" 104 "which:find <substring> in name of any tracked file" 105 "write-gitignore:write .gitignore.d/<repo> via git ls-files" 106 ) 107 108 args=( 109 '-c[source <file> prior to other configuration files]:config files:_path_files' 110 '-d[enable debug mode]' 111 '-v[enable verbose mode]' 112 '*:: :->subcommand_or_options_or_repo' 113 ) 114 115 _arguments -C ${args} && return 116 117 if [[ ${state} == "subcommand_or_options_or_repo" ]]; then 118 if (( CURRENT == 1 )); then 119 _describe -t subcommands 'vcsh sub-commands' subcommands 120 __vcsh_repositories 121 else 122 vcshcommand="${words[1]}" 123 if ! (( ${+functions[_vcsh-$vcshcommand]} )); then 124 # There is no handler function, so this is probably the name 125 # of a repository. Act accordingly. 126 _dispatch git git 127 else 128 curcontext="${curcontext%:*:*}:vcsh-${vcshcommand}:" 129 _call_function ret _vcsh-${vcshcommand} 130 fi 131 fi 132 fi 133} 134 135_vcsh "$@" 136