Store peeled refs in packed-refs file.
[gitweb.git] / contrib / completion / git-completion.bash
index f258f2f03e4a1ce2986c4d2fb645f7a895a90d3d..a43a177160b3b2952e4025bebc47c820ff4003f7 100755 (executable)
@@ -83,15 +83,15 @@ __git_remotes ()
 
 __git_complete_file ()
 {
-       local cur="${COMP_WORDS[COMP_CWORD]}"
+       local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        ?*:*)
-               local pfx ls ref="$(echo "$cur" | sed 's,:.*$,,')"
-               cur="$(echo "$cur" | sed 's,^.*:,,')"
+               ref="${cur%%:*}"
+               cur="${cur#*:}"
                case "$cur" in
                ?*/*)
-                       pfx="$(echo "$cur" | sed 's,/[^/]*$,,')"
-                       cur="$(echo "$cur" | sed 's,^.*/,,')"
+                       pfx="${cur%/*}"
+                       cur="${cur##*/}"
                        ls="$ref:$pfx"
                        pfx="$pfx/"
                        ;;
@@ -193,7 +193,7 @@ _git_fetch ()
        *)
                case "$cur" in
                *:*)
-               cur=$(echo "$cur" | sed 's/^.*://')
+                       cur="${cur#*:}"
                        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
                        ;;
                *)
@@ -222,11 +222,16 @@ _git_ls_tree ()
 
 _git_log ()
 {
-       local cur="${COMP_WORDS[COMP_CWORD]}"
+       local pfx cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
+       *...*)
+               pfx="${cur%...*}..."
+               cur="${cur#*...}"
+               COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
+               ;;
        *..*)
-               local pfx=$(echo "$cur" | sed 's/\.\..*$/../')
-               cur=$(echo "$cur" | sed 's/^.*\.\.//')
+               pfx="${cur%..*}.."
+               cur="${cur#*..}"
                COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
                ;;
        *)
@@ -282,7 +287,7 @@ _git_push ()
                        git-push)  remote="${COMP_WORDS[1]}" ;;
                        git)       remote="${COMP_WORDS[2]}" ;;
                        esac
-               cur=$(echo "$cur" | sed 's/^.*://')
+                       cur="${cur#*:}"
                        COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
                        ;;
                *)