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

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