Bash completion support for remotes in .git/config.
Now that Git natively supports remote specifications within the config file such as: [remote "origin"] url = ... we should provide bash completion support "out of the box" for these remotes, just like we do for the .git/remotes directory. Also cleaned up the __git_aliases expansion to use the same form of querying and filtering repo-config as this saves two fork/execs in the middle of a user prompted completion. Finally also forced the variable 'word' to be local within __git_aliased_command. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Nov 5, 2006 at 06:21 UTC
56fc25f21e280c4f3816e989b34d08d7d7cc59fc
1 file changed
+21
-5
contrib/completion/git-completion.bash
+21
-5
@@ -59,12 +59,21 @@ __git_refs2 ()
59
60
__git_remotes ()
61
{
62
- local i REVERTGLOB=$(shopt -p nullglob)
62
+ local i ngoff IFS=$'\n'
63
+ shopt -q nullglob || ngoff=1
64
shopt -s nullglob
65
for i in .git/remotes/*; do
66
echo ${i#.git/remotes/}
67
done
67
- $REVERTGLOB
68
+ [ "$ngoff" ] && shopt -u nullglob
69
+ for i in $(git repo-config --list); do
70
+ case "$i" in
71
+ remote.*.url=*)
72
+ i="${i#remote.}"
73
+ echo "${i/.url=*/}"
74
+ ;;
75
+ esac
76
+ done
77
}
78
79
__git_complete_file ()
@@ -103,13 +112,20 @@ __git_complete_file ()
112
113
__git_aliases ()
114
{
106
- git repo-config --list | grep '^alias\.' \
107
- | sed -e 's/^alias\.//' -e 's/=.*$//'
115
+ local i IFS=$'\n'
116
+ for i in $(git repo-config --list); do
117
+ case "$i" in
118
+ alias.*)
119
+ i="${i#alias.}"
120
+ echo "${i/=*/}"
121
+ ;;
122
+ esac
123
+ done
124
}
125
126
__git_aliased_command ()
127
{
112
- local cmdline=$(git repo-config alias.$1)
128
+ local word cmdline=$(git repo-config --get "alias.$1")
129
for word in $cmdline; do
130
if [ "${word##-*}" ]; then
131
echo $word