File: generate-bash-completion

package info (click to toggle)
git-hub 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 312 kB
  • sloc: python: 1,680; sh: 133; makefile: 56
file content (117 lines) | stat: -rwxr-xr-x 2,112 bytes parent folder | download
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
115
116
117
#!/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
}

_xfunc git __git_complete git-hub _git_hub
EOT