File: git-remote

package info (click to toggle)
yash 2.50-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,036 kB
  • sloc: ansic: 33,211; makefile: 839; sh: 477; sed: 16
file content (209 lines) | stat: -rw-r--r-- 4,774 bytes parent folder | download | duplicates (2)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# (C) 2011-2019 magicant

# Completion script for the "git-remote" command.
# Supports Git 1.7.7.

function completion/git-remote {
	WORDS=(git remote "${WORDS[2,-1]}")
	command -f completion//reexecute
}

function completion/git::remote:arg {

	while [ x"${WORDS[2]}" = x"-v" ] || [ x"${WORDS[2]}" = x"--verbose" ]; do
		WORDS=("${WORDS[1]}" "${WORDS[3,-1]}")
	done

	if [ ${WORDS[#]} -le 1 ]; then
		case ${TARGETWORD#"$PREFIX"} in
			(-v)  # avoid completing "-v" to "-vv"
				complete -P "$PREFIX" -- -v
				;;
			(-*)
				OPTIONS=( #>#
				"v --verbose; list remotes with URLs"
				) #<#
				command -f completion//parseoptions
				command -f completion//completeoptions
				;;
			(*) #>>#
				complete -P "$PREFIX" -D "add a remote" add
				complete -P "$PREFIX" -D "rename a remote" rename
				complete -P "$PREFIX" -D "remove a remote" rm
				complete -P "$PREFIX" -D "set the default branch of a remote" set-head
				complete -P "$PREFIX" -D "set remote-tracking branches" set-branches
				complete -P "$PREFIX" -D "set the URL of a remote" set-url
				complete -P "$PREFIX" -D "show a remote" show
				complete -P "$PREFIX" -D "delete remote-tracking branches that no longer exist on a remote" prune
				complete -P "$PREFIX" -D "fetch remotes" update
				;; #<<#
		esac
	else
		WORDS=("${WORDS[2,-1]}")
		if command -vf "completion/git::remote:${WORDS[1]}:arg" >/dev/null 2>&1; then
			command -f "completion/git::remote:${WORDS[1]}:arg"
		fi
	fi

}

function completion/git::remote:add:arg {

	OPTIONS=( #>#
	"f; fetch the remote after adding"
	"m:; specify a remote branch to be refs/remotes/*/HEAD"
	"--mirror:; specify a mirroring method"
	"--no-tags; don't fetch all remote tags after adding"
	"t:; specify a branch to track"
	"--tags; fetch all remote tags after adding"
	) #<#

	command -f completion//parseoptions
	case $ARGOPT in
		(-)
			command -f completion//completeoptions
			;;
		([mt])
			command -f completion/git::completeref --branches
			;;
		(--mirror) #>>#
			complete -P "$PREFIX" -D "mirror the remote into the local" fetch
			complete -P "$PREFIX" -D "set the remote.*.mirror option" push
			;; #<<#
		('')
			command -f completion/git::completeremote
			;;
	esac

}

function completion/git::remote:rename:arg {
	command -f completion/git::completeremote
}

function completion/git::remote:rm:arg {
	command -f completion/git::completeremote
}

function completion/git::remote:set-head:arg {

	case ${WORDS[1]} in
		(set-head)
			OPTIONS=( #>#
			"a --auto; query the remote default branch"
			"d --delete; remove the remote default branch"
			) #<#
			;;
		(set-branches)
			OPTIONS=( #>#
			"a --add; add branch; don't remove existing settings"
			) #<#
			;;
	esac

	command -f completion//parseoptions -es
	case $ARGOPT in
		(-)
			command -f completion//completeoptions
			;;
		('')
			command -f completion//getoperands
			if [ ${WORDS[#]} -eq 0 ]; then
				command -f completion/git::completeremote
			else
				command -f completion/git::completeremoteref \
					"${WORDS[1]}"
			fi
			;;
	esac

}

function completion/git::remote:set-branches:arg {
	command -f completion/git::remote:set-head:arg "$@"
}

function completion/git::remote:set-url:arg {

	OPTIONS=( #>#
	"--add; add a URL instead of changing URLs"
	"--delete; remove URLs instead of changing URLs"
	"--push; set push URLs instead of fetch URLs"
	) #<#

	command -f completion//parseoptions
	case $ARGOPT in
		(-)
			command -f completion//completeoptions
			;;
		('')
			command -f completion/git::completeremote
			;;
	esac

}

function completion/git::remote:show:arg {

	OPTIONS=( #>#
	"n; don't query the remote for the latest info"
	) #<#

	command -f completion//parseoptions
	case $ARGOPT in
		(-)
			command -f completion//completeoptions
			;;
		('')
			command -f completion/git::completeremote
			;;
	esac

}

function completion/git::remote:prune:arg {

	OPTIONS=( #>#
	"n --dry-run; don't actually prune, but show what would happen"
	) #<#

	command -f completion//parseoptions
	case $ARGOPT in
		(-)
			command -f completion//completeoptions
			;;
		('')
			command -f completion/git::completeremote
			;;
	esac

}

function completion/git::remote:update:arg {

	OPTIONS=( #>#
	"p --prune; delete remote-tracking branches that no longer exist on the remote"
	) #<#

	command -f completion//parseoptions
	case $ARGOPT in
		(-)
			command -f completion//completeoptions
			;;
		('')
			command -f completion/git::completeremote
			command -f completion/git::completeremotegroup
			;;
	esac

}

function completion/git::completeremotegroup {
	typeset name value
	while read -r name value; do
		complete -P "$PREFIX" -D "= $value" -- "${name#remotes.}"
	done 2>/dev/null <(git config --get-regexp 'remotes\..*')
}


# vim: set ft=sh ts=8 sts=8 sw=8 noet: