# HG changeset patch # User Daniel Kobras # Date 1134657614 -3600 # Node ID 851bc33ff545cfe182239f2c3369d462821610df # Parent 5c5aaaa9ab6fa697414d3dc78bf7a2edf95d58e7 Less annoying directory completion (see http://bugs.debian.org/343458) 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" 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. diff -r 5c5aaaa9ab6f -r 851bc33ff545 contrib/bash_completion --- a/contrib/bash_completion Thu Dec 15 15:39:20 2005 +0100 +++ b/contrib/bash_completion Thu Dec 15 15:40:14 2005 +0100 @@ -29,6 +29,14 @@ 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 @@ # 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 @@ ;; pull|push|outgoing|incoming) _hg_paths - COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) + _hg_repos ;; paths) _hg_paths @@ -151,7 +159,7 @@ if [ $count = 1 ]; then _hg_paths fi - COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) + _hg_repos ;; debugindex|debugindexdot) COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" ))