Skip to content
This repository was archived by the owner on May 1, 2018. It is now read-only.

Commit 81cc5d2

Browse files
committed
Merge branch 'feature/bash_completion'
2 parents 32019f2 + dd71e4a commit 81cc5d2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

README.rdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ you can have grb auto-completion by using the {git-remote-branch plugin}[https:/
3737
# ~/.zshrc
3838
plugins=(git git-remote-branch ...)
3939

40+
If you use bash, you can have grb auto-completion by souring `etc/grb-completion.bash`
41+
42+
# ~/.bash_profile
43+
source `gem contents git_remote_branch | grep grb-completion.bash`
44+
45+
or copy it to your desired destination and source it.
46+
4047
== Usage
4148

4249
Notes:

etc/grb-completion.bash

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
_grb()
2+
{
3+
local cur=${COMP_WORDS[COMP_CWORD]}
4+
local verb=${COMP_WORDS[1]}
5+
6+
local position=${COMP_CWORD}
7+
8+
if [[ "$verb" == "explain" ]]; then
9+
let "position = $position - 1"
10+
fi
11+
12+
case "$position" in
13+
1)
14+
COMPREPLY=( $(compgen -W "help explain create new delete destroy kill remove rm rename rn mv move track follow grab fetch" -- $cur) )
15+
;;
16+
2)
17+
18+
COMPREPLY=( $(compgen -W "$(_grb_branch)" -- $cur))
19+
;;
20+
3)
21+
22+
COMPREPLY=( $(compgen -W "$(_grb_remotes)" -- $cur))
23+
;;
24+
esac
25+
}
26+
27+
_grb_branch()
28+
{
29+
{
30+
git for-each-ref refs/remotes --format="%(refname:short)" |
31+
grep -v HEAD |
32+
sed 's/^.*\///g';
33+
git for-each-ref refs/heads --format="%(refname:short)";
34+
} | sort | uniq
35+
}
36+
37+
_grb_remotes()
38+
{
39+
local i IFS=$'\n'
40+
for i in $(git config --get-regexp 'remote\..*\.url' 2>/dev/null); do
41+
i="${i#remote.}"
42+
echo "${i/.url*/}"
43+
done
44+
}
45+
46+
complete -F _grb grb
47+

0 commit comments

Comments
 (0)