Skip to content

Commit cf6d40d

Browse files
authored
Improvements to Bash completion (#1210)
* Sort Bash completion functions * feat: add Bash completion for `git rename-branch` * feat: add Bash completion for `git rename-remote` * feat: add Bash completion for `git rename-tag` * fix: use default completion for `git rename-file` * Refactor rename completion functions common logic
1 parent 14586c7 commit cf6d40d

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

etc/bash_completion.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# shellcheck shell=bash
22
# bash completion support for git-extras.
33

4+
_git_authors(){
5+
__gitcomp "-l --list --no-email"
6+
}
7+
8+
_git_browse(){
9+
__git_complete_remote_or_refspec
10+
}
11+
12+
_git_browse_ci(){
13+
__git_complete_remote_or_refspec
14+
}
15+
16+
_git_brv(){
17+
__gitcomp "-r --reverse"
18+
}
19+
420
_git_changelog(){
521
local s_opts=( '-a' '-l' '-t' '-f' '-s' '-n' '-p' '-x' '-h' '?' )
622
local l_opts=(
@@ -22,14 +38,6 @@ _git_changelog(){
2238
__gitcomp "$merged_opts_str"
2339
}
2440

25-
_git_authors(){
26-
__gitcomp "-l --list --no-email"
27-
}
28-
29-
_git_brv(){
30-
__gitcomp "-r --reverse"
31-
}
32-
3341
_git_coauthor(){
3442
local oldIfs=$IFS
3543
IFS=$'\n'
@@ -136,6 +144,10 @@ _git_ignore(){
136144
esac
137145
}
138146

147+
_git_info(){
148+
__gitcomp "--color -c --no-config"
149+
}
150+
139151
_git_missing(){
140152
# Suggest all known refs
141153
__gitcomp "$(git for-each-ref --format='%(refname:short)')"
@@ -158,38 +170,40 @@ _git_reauthor(){
158170
__gitcomp "${comp}"
159171
}
160172

161-
_git_scp(){
162-
__git_complete_remote_or_refspec
173+
__git_extras_rename(){
174+
if ((COMP_CWORD == 2 || COMP_CWORD == 3)); then
175+
__gitcomp "$1"
176+
fi
163177
}
164178

165-
_git_stamp(){
166-
__gitcomp '--replace -r'
179+
_git_rename_branch(){
180+
__git_extras_rename "$(__git_heads)"
167181
}
168182

169-
_git_rscp(){
170-
__git_complete_remote_or_refspec
183+
_git_rename_remote(){
184+
__git_extras_rename "$(__git_remotes)"
171185
}
172186

173-
_git_squash(){
174-
__gitcomp "$(__git_heads)"
187+
_git_rename_tag(){
188+
__git_extras_rename "$(__git_tags)"
175189
}
176190

177-
_git_undo(){
178-
__gitcomp "--hard --soft -h -s"
191+
_git_rscp(){
192+
__git_complete_remote_or_refspec
179193
}
180194

181-
_git_info(){
182-
__gitcomp "--color -c --no-config"
195+
_git_scp(){
196+
__git_complete_remote_or_refspec
183197
}
184198

185-
_git_browse(){
186-
__git_complete_remote_or_refspec
199+
_git_squash(){
200+
__gitcomp "$(__git_heads)"
187201
}
188202

189-
_git_browse_ci(){
190-
__git_complete_remote_or_refspec
203+
_git_stamp(){
204+
__gitcomp '--replace -r'
191205
}
192206

193-
_git_rename_file() {
194-
__gitcomp "-h --help"
207+
_git_undo(){
208+
__gitcomp "--hard --soft -h -s"
195209
}

0 commit comments

Comments
 (0)