Package: mercurial
Version: 0.7-7
Severity: minor
Tags: patch

Moi!

The current bash completion script is quite painful in conjuntion with
deep directory trees because it adds a space after each successful
directory completion. Eg. "hg clone /ho<tab>" is completed to "hg clone
/home " when what you really want is "hg clone /home/" (assuming the
complete path to the repository looks like /home/foo/hg...).

That's because the 'complete' command does not know about the type of
completion it receives from the _hg shell function. When only a single
completion is returned, it assumes completion is complete and tells
readline to add a trailing space. This behaviour is usually wanted, but
not in the case of directory completion.

I've attached a patch that circumvents this problem by only returning
successful completions for directories that contain a .hg subdirectory.
If no repositories are found, no completions are returned either, and
bash falls back to ordinary (filename) completion. I find this behaviour
a lot less annoying than the current one.

Alternative: Use option nospace for the 'complete' command and let _hg
itself take care of adding a trailing space where appropriate. That's a
far more intrusive change, though.

Regards,

Daniel.

P.S.: Patch needs to be applied after bash_completion_is_not_a_script.patch.
--- mercurial-0.7/contrib/bash_completion       2005-09-16 23:02:33.000000000 
+0200
+++ mercurial-0.7/contrib/bash_completion       2005-12-15 13:13:15.000000000 
+0100
@@ -20,6 +20,14 @@
     COMPREPLY=([EMAIL PROTECTED]:-} $( compgen -W "$paths" -- "$cur" ))
 }
 
+_hg_repos()
+{
+    local i
+    for i in $( compgen -d -- "$cur" ); do
+        test ! -d "$i"/.hg || COMPREPLY=([EMAIL PROTECTED]:-} "$i")
+    done
+}
+
 _hg_status()
 {
     local files="$( hg status -$1 | cut -b 3- )"
@@ -83,11 +91,11 @@
     # global options
     case "$prev" in
        -R|--repository)
-           COMPREPLY=([EMAIL PROTECTED]:-} $( compgen -d -- "$cur" ))
+           _hg_repos
            return
        ;;
        --cwd)
-           COMPREPLY=([EMAIL PROTECTED]:-} $( compgen -d -- "$cur" ))
+           # Stick with default bash completion
            return
        ;;
     esac
@@ -114,7 +122,7 @@
        ;;
        pull|push|outgoing|incoming)
            _hg_paths
-           COMPREPLY=([EMAIL PROTECTED]:-} $( compgen -d -- "$cur" ))
+           _hg_repos
        ;;
        paths)
            _hg_paths
@@ -142,7 +150,7 @@
            if [ $count = 1 ]; then
                _hg_paths
            fi
-           COMPREPLY=([EMAIL PROTECTED]:-} $( compgen -d -- "$cur" ))
+            _hg_repos
        ;;
        debugindex|debugindexdot)
            COMPREPLY=([EMAIL PROTECTED]:-} $( compgen -f -X "!*.i" -- "$cur" ))

Reply via email to