]> git.madduck.net Git - code/vcsh.git/blob - _vcsh

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

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