My zsh configuration
git clone https://github.com/m-col/zshrc
Files | Refs | Readme

-rw-r--r-- zfunc/_gita


      1 #compdef gita
      2 
      3 __gita_get_repos() {
      4     local -a repositories
      5     repositories=($(_call_program commands gita ls))
      6     _describe -t repositories 'gita repositories' repositories
      7 }
      8 
      9 __gita_get_context() {
     10     local -a context
     11     context=(
     12         "auto"
     13         "none"
     14     )
     15     _describe -t context 'gita context' context
     16     __gita_get_groups
     17 }
     18 
     19 __gita_get_infos() {
     20     local -a all_infos infos_in_used infos_unused
     21     all_infos=($(_call_program commands gita info ll | cut -d ":" -f2))
     22     infos_in_used=($(echo ${all_infos[1]} | tr ',' ' '))
     23     infos_unused=($(echo ${all_infos[2]} | tr ',' ' '))
     24     _describe -t infos_used 'gita infos in used' infos_in_used
     25     _describe -t infos_unused 'gita infos unused' infos_unused
     26 }
     27 
     28 __gita_get_groups() {
     29     local -a groups
     30 
     31     groups=($(_call_program commands gita group ls))
     32     _describe -t groups 'gita groups' groups
     33 }
     34 
     35 __gita_commands() {
     36     local -a commands
     37     commands=(
     38         'add:Add repo(s)'
     39         'rm:remove repo(s)'
     40         'freeze:Print all repo information'
     41         'clone:Clone repos'
     42         'rename:Rename a repo'
     43         'flags:Git flags configuration'
     44         'color:Color configuration'
     45         'info:Information setting'
     46         'll:Display summary of all repos'
     47         'context:Set context'
     48         'ls:Show repo(s) or repo path'
     49         'group:Group repos'
     50         'super:Run any git command/alias'
     51         'shell:Run any shell command'
     52         'clear:Removes all groups and repositories'
     53     )
     54     _describe -t commands 'gita sub-commands' commands
     55 }
     56 
     57 # FUNCTION: _gita_add [[[
     58 _gita_add() {
     59     _arguments -A \
     60         '(-h --help)'{-h,--help}'[show this help message and exit]' \
     61         '(-n --dry-run)'{-n,--dry-run}'[dry run]' \
     62         '(-g --group)'{-g=,--group=}'[add repo(s) to the specified group]:Gita groups:__gita_get_groups' \
     63         '(-s --skip-modules)'{-s,--skip-modules}'[skip submodule repo(s)]' \
     64         '(-r --recursive)'{-r,--recursive}'[recursively add repo(s) in the given path(s)]' \
     65         '(-a --auto-group)'{-a,--auto-group}'[recursively add repo(s) in the given path(s) and create hierarchical groups based on folder structure]' \
     66         '(-b --bare)'{-b,--bare}'[add bare repo(s)]' \
     67         "(-h --help -)*:Directories:_directories"
     68     ret=0
     69 }
     70 #]]]
     71 
     72 # FUNCTION: _gita_rm [[[
     73 _gita_rm() {
     74     _arguments -A \
     75         '(-h --help)'{-h,--help}'[show this help message and exit]' \
     76         "(-h --help -)*:gita repositories:__gita_get_repos" &&
     77         ret=0
     78 }
     79 #]]]
     80 
     81 # FUNCTION: _gita_freeze [[[
     82 _gita_freeze() {
     83     _arguments -A \
     84         '(-h --help)'{-h,--help}'[show this help message and exit]' \
     85         '(-g --group)'{-g=,--group=}'[freeze repos in the specified group]:Gita groups:__gita_get_groups' &&
     86         ret=0
     87 }
     88 #]]]
     89 
     90 # FUNCTION: _gita_clone [[[
     91 _gita_clone() {
     92     _arguments -A \
     93         '(-h --help)'{-h,--help}'[show this help message and exit]' \
     94         '(-C --directory)'{-C=,--directory=}'[ Change to DIRECTORY before doing anything]:Directories:_directories' \
     95         '(-p --preserve-path)'{-p,--preserve-path}'[clone repo(s) in their original paths]' \
     96         '(-n --dry-run)'{-n,--dry-run}'[dry run]' \
     97         '(-g --group)'{-g=,--group=}'[If set, add repo to the specified group after cloning, otherwise add to gita without group]:Gita groups:__gita_get_groups' \
     98         '(-f --from-file)'{-f=,--from-file=}'[ If set, clone repos in a config file rendered from `gita freeze`]:File:_path_files' &&
     99         ret=0
    100 }
    101 #]]]
    102 
    103 # FUNCTION: _gita_rename [[[
    104 _gita_rename() {
    105     _arguments -A \
    106         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    107         "(-h --help -):Gita repositories:__gita_get_repos" &&
    108         ret=0
    109 }
    110 #]]]
    111 
    112 # FUNCTION: _gita_flags_commands[[[
    113 _gita_flags_commands() {
    114 
    115     local -a subcommands
    116     subcommands=(
    117         'll:Display repos with custom flags'
    118         'set:Set flags for repo'
    119     )
    120     _describe -t subcommands 'gita flag sub-commands' subcommands
    121 }
    122 #]]]
    123 
    124 # FUNCTION: _gita_flags_ll [[[
    125 _gita_flags_ll() {
    126     _arguments -A \
    127         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    128         ret=0
    129 }
    130 #]]]
    131 
    132 # FUNCTION: _gita_flags_set [[[
    133 _gita_flags_set() {
    134     _arguments -A \
    135         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    136         "(-h --help -):Gita repositories:__gita_get_repos" &&
    137         ret=0
    138 }
    139 #]]]
    140 
    141 # FUNCTION: _gita_flags[[[
    142 _gita_flags() {
    143     local curcontext="$curcontext" state state_descr line expl
    144     local tmp ret=1
    145     _arguments -A \
    146         '(-h --help)'{-h,--help}'[show this help message and exit]'
    147 
    148     _arguments -C \
    149         "1: :->cmds" \
    150         "*::arg:->args"
    151     case "$state" in
    152     cmds)
    153         _gita_flags_commands && return 0
    154         ;;
    155     args)
    156         local cmd="${line[1]}"
    157         curcontext="${curcontext%:*}-${cmd}:${curcontext##*:}"
    158         local completion_func="_gita_flags_${cmd//-/_}"
    159         _call_function ret "${completion_func}" && return ret
    160         _message "a completion function is not defined for command or alias: ${cmd}"
    161         return 1
    162         ;;
    163     esac
    164 }
    165 #]]]
    166 
    167 # FUNCTION: _gita_color_commands[[[
    168 _gita_color_commands() {
    169 
    170     local -a subcommands
    171     subcommands=(
    172         'll:Display available colors and the current branch coloring in the ll sub-command'
    173         'set:Set color for local/remote situation'
    174         'reset:Reset color scheme'
    175     )
    176     _describe -t subcommands 'gita color sub-commands' subcommands
    177 }
    178 #]]]
    179 
    180 # FUNCTION: _gita_color_ll [[[
    181 _gita_color_ll() {
    182     _arguments -A \
    183         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    184         ret=0
    185 }
    186 #]]]
    187 
    188 # FUNCTION: _gita_color_set [[[
    189 _gita_color_set() {
    190     _arguments -A \
    191         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    192         ret=0
    193 }
    194 #]]]
    195 
    196 # FUNCTION: _gita_color_reset [[[
    197 _gita_color_reset() {
    198     _arguments -A \
    199         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    200         ret=0
    201 }
    202 #]]]
    203 
    204 # FUNCTION: _gita_color[[[
    205 _gita_color() {
    206     local curcontext="$curcontext" state state_descr line expl
    207     local tmp ret=1
    208     _arguments -A \
    209         '(-h --help)'{-h,--help}'[show this help message and exit]'
    210 
    211     _arguments -C \
    212         "1: :->cmds" \
    213         "*::arg:->args"
    214     case "$state" in
    215     cmds)
    216         _gita_color_commands && return 0
    217         ;;
    218     args)
    219         local cmd="${line[1]}"
    220         curcontext="${curcontext%:*}-${cmd}:${curcontext##*:}"
    221         local completion_func="_gita_color_${cmd//-/_}"
    222         _call_function ret "${completion_func}" && return ret
    223         _message "a completion function is not defined for command or alias: ${cmd}"
    224         return 1
    225         ;;
    226     esac
    227 }
    228 #]]]
    229 
    230 # FUNCTION: _gita_info_commands[[[
    231 _gita_info_commands() {
    232 
    233     local -a subcommands
    234     subcommands=(
    235         'll:Show used and unused information items of the ll sub-command'
    236         'add:Enable information item'
    237         'rm:Disable information item'
    238     )
    239     _describe -t subcommands 'gita info sub-commands' subcommands
    240 }
    241 #]]]
    242 
    243 # FUNCTION: _gita_info_ll [[[
    244 _gita_info_ll() {
    245     _arguments -A \
    246         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    247         ret=0
    248 }
    249 #]]]
    250 
    251 # FUNCTION: _gita_info_add [[[
    252 _gita_info_add() {
    253     _arguments -A \
    254         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    255         "(-h --help -):Gita infos:__gita_get_infos" &&
    256         ret=0
    257 }
    258 #]]]
    259 
    260 # FUNCTION: _gita_info_rm [[[
    261 _gita_info_rm() {
    262     _arguments -A \
    263         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    264         "(-h --help -):Gita infos:__gita_get_infos" &&
    265         ret=0
    266 }
    267 #]]]
    268 
    269 # FUNCTION: _gita_info[[[
    270 _gita_info() {
    271     local curcontext="$curcontext" state state_descr line expl
    272     local tmp ret=1
    273     _arguments -A \
    274         '(-h --help)'{-h,--help}'[show this help message and exit]'
    275 
    276     _arguments -C \
    277         "1: :->cmds" \
    278         "*::arg:->args"
    279     case "$state" in
    280     cmds)
    281         _gita_info_commands && return 0
    282         ;;
    283     args)
    284         local cmd="${line[1]}"
    285         curcontext="${curcontext%:*}-${cmd}:${curcontext##*:}"
    286         local completion_func="_gita_info_${cmd//-/_}"
    287         _call_function ret "${completion_func}" && return ret
    288         _message "a completion function is not defined for command or alias: ${cmd}"
    289         return 1
    290         ;;
    291     esac
    292 }
    293 #]]]
    294 
    295 # FUNCTION: _gita_ll [[[
    296 _gita_ll() {
    297     _arguments -A \
    298         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    299         '(-C --no-colors)'{-C,--no-colors}'[Disable coloring on the branch names]' \
    300         '(-g)'-g'[Show repo summaries by group]' \
    301         "(-h --help -):Groups name:__gita_get_groups" &&
    302         ret=0
    303 }
    304 #]]]
    305 
    306 # FUNCTION: _gita_context [[[
    307 _gita_context() {
    308     _arguments -A \
    309         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    310         "(-h --help -):Gita context:__gita_get_context" &&
    311         ret=0
    312 }
    313 #]]]
    314 
    315 # FUNCTION: _gita_ls [[[
    316 _gita_ls() {
    317     _arguments -A \
    318         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    319         "(-h --help -):Gita repositories:__gita_get_repos" &&
    320         ret=0
    321 }
    322 #]]]
    323 
    324 # FUNCTION: _gita_group_commands[[[
    325 _gita_group_commands() {
    326 
    327     local -a subcommands
    328     subcommands=(
    329         'll:List all groups with repos.'
    330         'ls:List all group names'
    331         'add:Add repo(s) to a group'
    332         'rmrepo:remove repo(s) from a group'
    333         'rename:Change group name'
    334         'rm:Remove group(s)'
    335     )
    336     _describe -t subcommands 'gita group sub-commands' subcommands
    337 }
    338 #]]]
    339 
    340 # FUNCTION: _gita_group_ll [[[
    341 _gita_group_ll() {
    342     _arguments -A \
    343         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    344         "(-h --help -):Groups name:__gita_get_groups" &&
    345         ret=0
    346 }
    347 #]]]
    348 
    349 # FUNCTION: _gita_group_ls [[[
    350 _gita_group_ls() {
    351     _arguments -A \
    352         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    353         ret=0
    354 }
    355 #]]]
    356 
    357 # FUNCTION: _gita_group_add [[[
    358 _gita_group_add() {
    359     _arguments -A \
    360         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    361         '(-n --name)'{-n=,--name=}'[group-name,]:Groups name:__gita_get_groups' \
    362         '(-p --path)'{-p=,--path=}'[group-path]:Group path:_directories' \
    363         "(-h --help -)*:Gita repositories:__gita_get_repos" &&
    364         ret=0
    365 }
    366 #]]]
    367 
    368 # FUNCTION: _gita_group_rmrepo [[[
    369 _gita_group_rmrepo() {
    370     _arguments -A \
    371         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    372         '(-n --name)'{-n=,--name=}'[group-name,]:Groups name:__gita_get_groups' \
    373         "(-h --help -)*:Gita repositories:__gita_get_repos" &&
    374         ret=0
    375 }
    376 #]]]
    377 
    378 # FUNCTION: _gita_group_rename [[[
    379 _gita_group_rename() {
    380     _arguments -A \
    381         '(-h --help -)'{-h,--help}'[show this help message and exit]' &&
    382         ret=0
    383 }
    384 #]]]
    385 
    386 # FUNCTION: _gita_group_rm [[[
    387 _gita_group_rm() {
    388     _arguments -A \
    389         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    390         "(-h --help -)*:Groups name:__gita_get_groups" &&
    391         ret=0
    392 }
    393 #]]]
    394 
    395 # FUNCTION: _gita_group[[[
    396 _gita_group() {
    397     local curcontext="$curcontext" state state_descr line expl
    398     local tmp ret=1
    399     _arguments -A \
    400         '(-h --help)'{-h,--help}'[show this help message and exit]'
    401 
    402     _arguments -C \
    403         "1: :->cmds" \
    404         "*::arg:->args"
    405     case "$state" in
    406     cmds)
    407         _gita_group_commands && return 0
    408         ;;
    409     args)
    410         local cmd="${line[1]}"
    411         curcontext="${curcontext%:*}-${cmd}:${curcontext##*:}"
    412         local completion_func="_gita_group_${cmd//-/_}"
    413         _call_function ret "${completion_func}" && return ret
    414         _message "a completion function is not defined for command or alias: ${cmd}"
    415         return 1
    416         ;;
    417     esac
    418 }
    419 #]]]
    420 
    421 # FUNCTION: _gita_super [[[
    422 _gita_super() {
    423     _arguments -A \
    424         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    425         '(-q --quote-mode)'{-q,--quote-mode}'[use quote mode]' &&
    426         ret=0
    427 }
    428 #]]]
    429 
    430 # FUNCTION: _gita_shell [[[
    431 _gita_shell() {
    432     _arguments -A \
    433         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    434         '(-q --quote-mode)'{-q,--quote-mode}'[use quote mode]' &&
    435         ret=0
    436 }
    437 #]]]
    438 
    439 # FUNCTION: _gita_clear [[[
    440 _gita_clear() {
    441     _arguments -A \
    442         '(-h --help)'{-h,--help}'[show this help message and exit]' &&
    443         ret=0
    444 }
    445 #]]]
    446 
    447 # FUNCTION: _gita [[[
    448 _gita() {
    449     local curcontext="$curcontext" state state_descr line expl
    450     local tmp ret=1
    451     _arguments -A \
    452         '(-h --help)'{-h,--help}'[show this help message and exit]' \
    453         '(-v --version)'{-v,--version}'[show program'\''s version number and exit]'
    454 
    455     _arguments -C \
    456         "1: :->cmds" \
    457         "*::arg:->args"
    458     case "$state" in
    459     cmds)
    460         __gita_commands && return 0
    461         ;;
    462     args)
    463         local cmd="${line[1]}"
    464         curcontext="${curcontext%:*}-${cmd}:${curcontext##*:}"
    465         local completion_func="_gita_${cmd//-/_}"
    466         _call_function ret "${completion_func}" && return ret
    467         _message "a completion function is not defined for command or alias: ${cmd}"
    468         return 1
    469         ;;
    470     esac
    471 } # ]]]
    472 
    473 _gita "$@"
    474