contrib/bash_completion
changeset 1587 851bc33ff545
parent 1556 561b17b7d3a2
child 1638 1c75487badd6
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -29,6 +29,14 @@ shopt -s extglob
     COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" ))
 }
 
+_hg_repos()
+{
+    local i
+    for i in $( compgen -d -- "$cur" ); do
+        test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
+    done
+}
+
 _hg_status()
 {
     local files="$( hg status -$1 | cut -b 3- )"
@@ -92,11 +100,11 @@ shopt -s extglob
     # global options
     case "$prev" in
 	-R|--repository)
-	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
+	    _hg_repos
 	    return
 	;;
 	--cwd)
-	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
+	    # Stick with default bash completion
 	    return
 	;;
     esac
@@ -123,7 +131,7 @@ shopt -s extglob
 	;;
 	pull|push|outgoing|incoming)
 	    _hg_paths
-	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
+	    _hg_repos
 	;;
 	paths)
 	    _hg_paths
@@ -151,7 +159,7 @@ shopt -s extglob
 	    if [ $count = 1 ]; then
 		_hg_paths
 	    fi
-	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
+            _hg_repos
 	;;
 	debugindex|debugindexdot)
 	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" ))