[PATCH] completion: add option completion for most builtin commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These commands can take options and use parse-options so it's quite
easy to allow option completion. This does not pollute the command
name completion though. "git <tab>" will show you the same set as
before. This only kicks in when you type the correct command name.

Some other builtin commands are not still added because either they
don't use parse-options, or they are deprecated, or they are those
-helper commands that are used to move some logic back in C for
sh-based commands.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 contrib/completion/git-completion.bash | 276 +++++++++++++++++++++++++
 1 file changed, 276 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6da95b8095..0cd9180f48 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1202,6 +1202,15 @@ _git_bisect ()
 	esac
 }
 
+_git_blame() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin blame
+		return
+		;;
+	esac
+}
+
 _git_branch ()
 {
 	local i c=1 only_local_ref="n" has_r="n"
@@ -1254,6 +1263,42 @@ _git_bundle ()
 	esac
 }
 
+_git_cat_file() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin cat-file
+		return
+		;;
+	esac
+}
+
+_git_check_attr() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin check-attr
+		return
+		;;
+	esac
+}
+
+_git_check_ignore() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin check-ignore
+		return
+		;;
+	esac
+}
+
+_git_check_mailmap() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin check-mailmap
+		return
+		;;
+	esac
+}
+
 _git_checkout ()
 {
 	__git_has_doubledash && return
@@ -1278,6 +1323,15 @@ _git_checkout ()
 	esac
 }
 
+_git_checkout_index() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin checkout-index
+		return
+		;;
+	esac
+}
+
 _git_cherry ()
 {
 	__git_complete_refs
@@ -1326,6 +1380,15 @@ _git_clone ()
 	esac
 }
 
+_git_column() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin column
+		return
+		;;
+	esac
+}
+
 __git_untracked_file_modes="all no normal"
 
 _git_commit ()
@@ -1365,6 +1428,15 @@ _git_commit ()
 	fi
 }
 
+_git_count_objects() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin count-objects
+		return
+		;;
+	esac
+}
+
 _git_describe ()
 {
 	case "$cur" in
@@ -1446,6 +1518,15 @@ _git_difftool ()
 	__git_complete_revlist_file
 }
 
+_git_fast_export() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin fast-export
+		return
+		;;
+	esac
+}
+
 __git_fetch_recurse_submodules="yes on-demand no"
 
 _git_fetch ()
@@ -1573,6 +1654,15 @@ _git_grep ()
 	__git_complete_refs
 }
 
+_git_hash_object() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin hash-object
+		return
+		;;
+	esac
+}
+
 _git_help ()
 {
 	case "$cur" in
@@ -1590,6 +1680,15 @@ _git_help ()
 		"
 }
 
+_git_index_pack() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin index-pack
+		return
+		;;
+	esac
+}
+
 _git_init ()
 {
 	case "$cur" in
@@ -1606,6 +1705,15 @@ _git_init ()
 	esac
 }
 
+_git_interpret_trailers() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin interpret-trailers
+		return
+		;;
+	esac
+}
+
 _git_ls_files ()
 {
 	case "$cur" in
@@ -1765,6 +1873,15 @@ _git_merge ()
 	__git_complete_refs
 }
 
+_git_merge_file() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin merge-file
+		return
+		;;
+	esac
+}
+
 _git_mergetool ()
 {
 	case "$cur" in
@@ -1790,6 +1907,15 @@ _git_merge_base ()
 	__git_complete_refs
 }
 
+_git_mktree() {
+	case "$cur" in
+	--*)
+		__gitcomp_builtin mktree
+		return
+		;;
+	esac
+}
+
 _git_mv ()
 {
 	case "$cur" in
@@ -1853,6 +1979,46 @@ _git_notes ()
 	esac
 }
 
+_git_pack_objects ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin pack-objects
+		return
+		;;
+	esac
+}
+
+_git_pack_refs ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin pack-refs
+		return
+		;;
+	esac
+}
+
+_git_prune ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin prune
+		return
+		;;
+	esac
+}
+
+_git_prune_packed ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin prune-packed
+		return
+		;;
+	esac
+}
+
 _git_pull ()
 {
 	__git_complete_strategy && return
@@ -1925,6 +2091,16 @@ _git_push ()
 	__git_complete_remote_or_refspec
 }
 
+_git_read_tree ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin read-tree
+		return
+		;;
+	esac
+}
+
 _git_rebase ()
 {
 	__git_find_repo_path
@@ -1974,6 +2150,16 @@ _git_reflog ()
 	fi
 }
 
+_git_repack ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin repack
+		return
+		;;
+	esac
+}
+
 __git_send_email_confirm_options="always never auto cc compose"
 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
 
@@ -2031,6 +2217,26 @@ _git_send_email ()
 	__git_complete_revlist
 }
 
+_git_send_pack ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin send-pack
+		return
+		;;
+	esac
+}
+
+_git_show_ref ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin show-ref
+		return
+		;;
+	esac
+}
+
 _git_stage ()
 {
 	_git_add
@@ -2082,6 +2288,26 @@ _git_status ()
 	__git_complete_index_file "$complete_opt"
 }
 
+_git_stripspace ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin stripspace
+		return
+		;;
+	esac
+}
+
+_git_symbolic_ref ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin symbolic-ref
+		return
+		;;
+	esac
+}
+
 __git_config_get_set_variables ()
 {
 	local prevword word config_file= c=$cword
@@ -2998,6 +3224,46 @@ _git_tag ()
 	esac
 }
 
+_git_update_index ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin update-index
+		return
+		;;
+	esac
+}
+
+_git_update_ref ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin update-ref
+		return
+		;;
+	esac
+}
+
+_git_verify_commit ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin verify-commit
+		return
+		;;
+	esac
+}
+
+_git_verify_tag ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin verify-tag
+		return
+		;;
+	esac
+}
+
 _git_whatchanged ()
 {
 	_git_log
@@ -3032,6 +3298,16 @@ _git_worktree ()
 	fi
 }
 
+_git_write_tree ()
+{
+	case "$cur" in
+	--*)
+		__gitcomp_builtin write-tree
+		return
+		;;
+	esac
+}
+
 __git_main ()
 {
 	local i c=1 command __git_dir __git_repo_path
-- 
2.17.0.rc0.348.gd5a49e0b6f




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux