Skip to content

Commit 6e31b86

Browse files
spearceJunio C Hamano
authored andcommitted
Teach bash about git log/show/whatchanged options.
Typing out options to git log/show/whatchanged can take a while, but we can easily complete them with bash. So list the most common ones, especially --pretty=online|short|medium|... so that users don't need to type everything out. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 61d926a commit 6e31b86

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

contrib/completion/git-completion.bash

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,29 @@ _git_ls_tree ()
358358

359359
_git_log ()
360360
{
361+
local cur="${COMP_WORDS[COMP_CWORD]}"
362+
case "$cur" in
363+
--pretty=*)
364+
COMPREPLY=($(compgen -W "
365+
oneline short medium full fuller email raw
366+
" -- "${cur##--pretty=}"))
367+
return
368+
;;
369+
--*)
370+
COMPREPLY=($(compgen -W "
371+
--max-count= --max-age= --since= --after=
372+
--min-age= --before= --until=
373+
--root --not --topo-order --date-order
374+
--no-merges
375+
--abbrev-commit --abbrev=
376+
--relative-date
377+
--author= --committer= --grep=
378+
--all-match
379+
--pretty= --name-status --name-only
380+
" -- "$cur"))
381+
return
382+
;;
383+
esac
361384
__git_complete_revlist
362385
}
363386

@@ -474,12 +497,6 @@ _git_reset ()
474497
COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
475498
}
476499

477-
_git_show ()
478-
{
479-
local cur="${COMP_WORDS[COMP_CWORD]}"
480-
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
481-
}
482-
483500
_git ()
484501
{
485502
local i c=1 command __git_dir
@@ -526,7 +543,7 @@ _git ()
526543
push) _git_push ;;
527544
rebase) _git_rebase ;;
528545
reset) _git_reset ;;
529-
show) _git_show ;;
546+
show) _git_log ;;
530547
show-branch) _git_log ;;
531548
whatchanged) _git_log ;;
532549
*) COMPREPLY=() ;;
@@ -559,7 +576,7 @@ complete -o default -o nospace -F _git_pull git-pull
559576
complete -o default -o nospace -F _git_push git-push
560577
complete -o default -F _git_rebase git-rebase
561578
complete -o default -F _git_reset git-reset
562-
complete -o default -F _git_show git-show
579+
complete -o default -F _git_log git-show
563580
complete -o default -o nospace -F _git_log git-show-branch
564581
complete -o default -o nospace -F _git_log git-whatchanged
565582

@@ -579,6 +596,7 @@ complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
579596
complete -o default -F _git_merge_base git-merge-base.exe
580597
complete -o default -F _git_name_rev git-name-rev.exe
581598
complete -o default -o nospace -F _git_push git-push.exe
599+
complete -o default -o nospace -F _git_log git-show.exe
582600
complete -o default -o nospace -F _git_log git-show-branch.exe
583601
complete -o default -o nospace -F _git_log git-whatchanged.exe
584602
fi

0 commit comments

Comments
 (0)