Skip to content

Commit

Permalink
Bash completion support for remotes in .git/config.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Nov 5, 2006
1 parent 76c3eb5 commit 56fc25f
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,21 @@ __git_refs2 ()

__git_remotes ()
{
local i REVERTGLOB=$(shopt -p nullglob)
local i ngoff IFS=$'\n'
shopt -q nullglob || ngoff=1
shopt -s nullglob
for i in .git/remotes/*; do
echo ${i#.git/remotes/}
done
$REVERTGLOB
[ "$ngoff" ] && shopt -u nullglob
for i in $(git repo-config --list); do
case "$i" in
remote.*.url=*)
i="${i#remote.}"
echo "${i/.url=*/}"
;;
esac
done
}

__git_complete_file ()
Expand Down Expand Up @@ -103,13 +112,20 @@ __git_complete_file ()

__git_aliases ()
{
git repo-config --list | grep '^alias\.' \
| sed -e 's/^alias\.//' -e 's/=.*$//'
local i IFS=$'\n'
for i in $(git repo-config --list); do
case "$i" in
alias.*)
i="${i#alias.}"
echo "${i/=*/}"
;;
esac
done
}

__git_aliased_command ()
{
local cmdline=$(git repo-config alias.$1)
local word cmdline=$(git repo-config --get "alias.$1")
for word in $cmdline; do
if [ "${word##-*}" ]; then
echo $word
Expand Down

0 comments on commit 56fc25f

Please sign in to comment.