]> 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:

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