@matheusbsbs / matheus-bagliano / commits / 5de40f59d4
Fork 0

Teach bash about git-repo-config.

This is a really ugly completion script for git-repo-config, but it has some nice properties. I've added all of the documented configuration parameters from Documentation/config.txt to the script, allowing the user to complete any standard configuration parameter name. We also have some intelligence for the remote.*.* and branch.*.* keys by completing not only the key name (e.g. remote.origin) but also the values (e.g. remote.*.fetch completes to the branches available on the corresponding remote). Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Nov 27, 2006 at 04:44 UTC 5de40f59d4954738448e238b06eed72f73cca740
1 file changed +154
contrib/completion/git-completion.bash
+154
@@ -43,6 +43,27 @@ __git_ps1 ()
43 fi
44 }
45
46 +__git_heads ()
47 +{
48 + local cmd i is_hash=y dir="${1:-$(__gitdir)}"
49 + if [ -d "$dir" ]; then
50 + for i in $(git --git-dir="$dir" \
51 + for-each-ref --format='%(refname)' \
52 + refs/heads ); do
53 + echo "${i#refs/heads/}"
54 + done
55 + return
56 + fi
57 + for i in $(git-ls-remote "$dir" 2>/dev/null); do
58 + case "$is_hash,$i" in
59 + y,*) is_hash=n ;;
60 + n,*^{}) is_hash=y ;;
61 + n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
62 + n,*) is_hash=y; echo "$i" ;;
63 + esac
64 + done
65 +}
66 +
67 __git_refs ()
68 {
69 local cmd i is_hash=y dir="${1:-$(__gitdir)}"
@@ -91,6 +112,23 @@ __git_refs2 ()
112 done
113 }
114
115 +__git_refs_remotes ()
116 +{
117 + local cmd i is_hash=y
118 + for i in $(git-ls-remote "$1" 2>/dev/null); do
119 + case "$is_hash,$i" in
120 + n,refs/heads/*)
121 + is_hash=y
122 + echo "$i:refs/remotes/$1/${i#refs/heads/}"
123 + ;;
124 + y,*) is_hash=n ;;
125 + n,*^{}) is_hash=y ;;
126 + n,refs/tags/*) is_hash=y;;
127 + n,*) is_hash=y; ;;
128 + esac
129 + done
130 +}
131 +
132 __git_remotes ()
133 {
134 local i ngoff IFS=$'\n' d="$(__gitdir)"
@@ -500,6 +538,119 @@ _git_rebase ()
538 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
539 }
540
541 +_git_repo_config ()
542 +{
543 + local cur="${COMP_WORDS[COMP_CWORD]}"
544 + local prv="${COMP_WORDS[COMP_CWORD-1]}"
545 + case "$prv" in
546 + branch.*.remote)
547 + COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
548 + return
549 + ;;
550 + branch.*.merge)
551 + COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
552 + return
553 + ;;
554 + remote.*.fetch)
555 + local remote="${prv#remote.}"
556 + remote="${remote%.fetch}"
557 + COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
558 + -- "$cur"))
559 + return
560 + ;;
561 + remote.*.push)
562 + local remote="${prv#remote.}"
563 + remote="${remote%.push}"
564 + COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
565 + for-each-ref --format='%(refname):%(refname)' \
566 + refs/heads)" -- "$cur"))
567 + return
568 + ;;
569 + *.*)
570 + COMPREPLY=()
571 + return
572 + ;;
573 + esac
574 + case "$cur" in
575 + --*)
576 + COMPREPLY=($(compgen -W "
577 + --global --list --replace-all
578 + --get --get-all --get-regexp
579 + --unset --unset-all
580 + " -- "$cur"))
581 + return
582 + ;;
583 + branch.*.*)
584 + local pfx="${cur%.*}."
585 + cur="${cur##*.}"
586 + COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
587 + return
588 + ;;
589 + branch.*)
590 + local pfx="${cur%.*}."
591 + cur="${cur#*.}"
592 + COMPREPLY=($(compgen -P "$pfx" -S . \
593 + -W "$(__git_heads)" -- "$cur"))
594 + return
595 + ;;
596 + remote.*.*)
597 + local pfx="${cur%.*}."
598 + cur="${cur##*.}"
599 + COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
600 + return
601 + ;;
602 + remote.*)
603 + local pfx="${cur%.*}."
604 + cur="${cur#*.}"
605 + COMPREPLY=($(compgen -P "$pfx" -S . \
606 + -W "$(__git_remotes)" -- "$cur"))
607 + return
608 + ;;
609 + esac
610 + COMPREPLY=($(compgen -W "
611 + apply.whitespace
612 + core.fileMode
613 + core.gitProxy
614 + core.ignoreStat
615 + core.preferSymlinkRefs
616 + core.logAllRefUpdates
617 + core.repositoryFormatVersion
618 + core.sharedRepository
619 + core.warnAmbiguousRefs
620 + core.compression
621 + core.legacyHeaders
622 + i18n.commitEncoding
623 + diff.color
624 + diff.renameLimit
625 + diff.renames
626 + pager.color
627 + status.color
628 + log.showroot
629 + show.difftree
630 + showbranch.default
631 + whatchanged.difftree
632 + http.sslVerify
633 + http.sslCert
634 + http.sslKey
635 + http.sslCAInfo
636 + http.sslCAPath
637 + http.maxRequests
638 + http.lowSpeedLimit http.lowSpeedTime
639 + http.noEPSV
640 + pack.window
641 + repack.useDeltaBaseOffset
642 + pull.octopus pull.twohead
643 + merge.summary
644 + receive.unpackLimit
645 + receive.denyNonFastForwards
646 + user.name user.email
647 + tar.umask
648 + gitcvs.enabled
649 + gitcvs.logfile
650 + branch. remote.
651 + " -- "$cur"))
652 +}
653 +
654 _git_reset ()
655 {
656 local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -552,6 +703,7 @@ _git ()
703 pull) _git_pull ;;
704 push) _git_push ;;
705 rebase) _git_rebase ;;
706 + repo-config) _git_repo_config ;;
707 reset) _git_reset ;;
708 show) _git_log ;;
709 show-branch) _git_log ;;
@@ -585,6 +737,7 @@ complete -o default -F _git_name_rev git-name-rev
737 complete -o default -o nospace -F _git_pull git-pull
738 complete -o default -o nospace -F _git_push git-push
739 complete -o default -F _git_rebase git-rebase
740 +complete -o default -F _git_repo_config git-repo-config
741 complete -o default -F _git_reset git-reset
742 complete -o default -F _git_log git-show
743 complete -o default -o nospace -F _git_log git-show-branch
@@ -606,6 +759,7 @@ complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
759 complete -o default -F _git_merge_base git-merge-base.exe
760 complete -o default -F _git_name_rev git-name-rev.exe
761 complete -o default -o nospace -F _git_push git-push.exe
762 +complete -o default -F _git_repo_config git-repo-config
763 complete -o default -o nospace -F _git_log git-show.exe
764 complete -o default -o nospace -F _git_log git-show-branch.exe
765 complete -o default -o nospace -F _git_log git-whatchanged.exe