Debian Codegraph @

extra/zsh-completion/_legit

raw
1 #compdef legit
2 # ------------------------------------------------------------------------------
3 # Description
4 # -----------
5 #
6 # Completion script for legit (https://github.com/kennethreitz/legit).
7 #
8 # ------------------------------------------------------------------------------
9 # Authors
10 # -------
11 #
12 # * Ryan James (https://github.com/autoplectic)
13 #
14 # ------------------------------------------------------------------------------
15
16
17 _legit ()
18 {
19 local curcontext="$curcontext" state line
20 typeset -A opt_args
21
22 _arguments -C \
23 '1:command:->command' \
24 '*::options:->options'
25
26 local -a subcommands
27 subcommands=(
28 'settings: Display and edit the current Legit settings.'
29 'branches: Get a nice pretty list of available branches. Allows wildcard branch name matching.'
30 'sync: Synchronizes the given branch. Defaults to current branch. Stash, Fetch, Auto-Merge/Rebase, Push, and Unstash. You can only sync published branches.'
31 'switch: Switches to specified branch. Defaults to current branch. Automatically stashes and unstashes any changes.'
32 'publish: Publishes specified branch to the remote.'
33 'unpublish: Removes specified branch from the remote.'
34 'help: Displays help for legit command.'
35 )
36
37 case $state in
38 (command)
39 _describe -t commands 'legit' subcommands
40 ;;
41
42 (options)
43 case $line[1] in
44 (settings|branches)
45 ;;
46 (sy|sync|sw|switch|pub|publish|unp|unpublish|rs)
47 _arguments \
48 ':branch:__git_branch_names'
49 ;;
50 (help)
51 _describe -t commands 'legit' subcommands
52 ;;
53 esac
54 esac
55 }
56
57
58 # Helper functions copied from Completion/Unix/Command/_git (a2098b0) {{{
59 # The approach to trigger the load of _git completion did not work (recursion, ...):
60 # https://dev.0x50.de/projects/ftzsh/repository/revisions/master/entry/functions/_ta#L17
61 (( $+functions[__git_branch_names] )) ||
62 __git_branch_names () {
63 local expl
64 declare -a branch_names
65
66 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
67 __git_command_successful $pipestatus || return 1
68
69 _wanted branch-names expl branch-name compadd $* - $branch_names
70 }
71
72 (( $+functions[__git_command_successful] )) ||
73 __git_command_successful () {
74 if (( ${#*:#0} > 0 )); then
75 _message 'not a git repository'
76 return 1
77 fi
78 return 0
79 }
80 # }}}
81
82 _legit
83
84
85 # -*- mode: zsh; -*-
86 # vim: ft=zsh sw=8 ts=8 et