-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
generate-bash-completion
executable file
·115 lines (102 loc) · 2.02 KB
/
generate-bash-completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
set -e
# Generates a bash-completion script as a git subcommand to stdout
#
# Based on the _git_svn completion function in git distribution's bash
# completion.
PYTHON=${PYTHON:-python3}
issue_arg_cmds="issue-show issue-update issue-comment issue-close pull-attach"
pull_arg_cmds="pull-show pull-update pull-comment pull-close"
get_opts()
{
$PYTHON git-hub "$@" -h > /dev/null || exit 1
$PYTHON git-hub "$@" -h |
sed -n 's/^ \(-., \)\?\(--[^ ]\+\) .*$/\2/p' |
tr '\n' ' '
$PYTHON git-hub "$@" -h |
sed -n 's/^ \(-. \([A-Z]\+\), \)\?\(--[^ ]\+\) \2\( .*\)\?$/\3=/p' |
tr '\n' ' '
}
get_cmds()
{
$PYTHON git-hub "$@" -h > /dev/null || exit 1
$PYTHON git-hub "$@" -h | sed -n 's/,/ /g;s/^ {\(.*\)}$/\1/p'
}
cmds=$(get_cmds)
cat <<EOT
__git_hub_get_issues()
{
git hub issue list 2> /dev/null |
sed -n 's/^\[\([0-9]\+\)\] .*$/\1/p' | tr '\n' ' '
}
__git_hub_get_pulls()
{
git hub pull list 2> /dev/null |
sed -n 's/^\[\([0-9]\+\)\] .*$/\1/p' | tr '\n' ' '
}
_git_hub ()
{
local subcommand="\$(__git_find_on_cmdline "$cmds")"
if [ -z "\$subcommand" ]; then
case "\$cur" in
--*)
__gitcomp "$(get_opts)"
;;
*)
__gitcomp "$cmds"
;;
esac
else
case "\$subcommand" in
EOT
for cmd in $cmds
do
subcmds=$(get_cmds $cmd)
cat <<EOT
$cmd)
local subsubcommand="\$(__git_find_on_cmdline "$subcmds")"
if [ -z "\$subsubcommand" ]; then
case "\$cur" in
--*)
__gitcomp "$(get_opts $cmd)"
;;
*)
__gitcomp "$subcmds"
;;
esac
else
case "\$subsubcommand,\$cur" in
EOT
for subcmd in $subcmds
do
cat <<EOT
$subcmd,--*)
__gitcomp "$(get_opts $cmd $subcmd)"
;;
EOT
done
reply="COMPREPLY=()"
if [ "$issue_arg_cmds" != "${issue_arg_cmds/$cmd-$subcmd/}" ]
then
reply="__gitcomp \"\$(__git_hub_get_issues)\""
elif [ "$pull_arg_cmds" != "${pull_arg_cmds/$cmd-$subcmd/}" ]
then
reply="__gitcomp \"\$(__git_hub_get_pulls)\""
fi
cat <<EOT
*)
$reply
;;
esac
fi
;;
EOT
done
cat <<EOT
*)
COMPREPLY=()
;;
esac
fi
}
EOT