[PATCH 3 of 5] teach bash_completion about --cwd

Alexis S. L. Carvalho alexis at cecm.usp.br
Sun Aug 28 20:43:15 CDT 2005


# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Node ID 93433c2989a15f3ca3b60799590b0a41c500a97f
# Parent  93b323240bafe204769a7ae6f8b02ca86fd06009
teach bash_completion about --cwd

diff -r 93b323240baf -r 93433c2989a1 contrib/bash_completion
--- a/contrib/bash_completion	Mon Aug 29 01:12:06 2005
+++ b/contrib/bash_completion	Mon Aug 29 01:12:06 2005
@@ -56,19 +56,22 @@
 _hg()
 {
     local cur prev cmd opts i
+    # global options that receive an argument
+    local global_args='--cwd|-R|--repository'
 
     COMPREPLY=()
     cur="$2"
     prev="$3"
 
     # searching for the command 
-    # (first non-option argument that doesn't follow -R/--repository)
+    # (first non-option argument that doesn't follow a global option that
+    #  receives an argument)
     for (( i=1; $i<=$COMP_CWORD; i++ )); do
-	if [[ ${COMP_WORDS[i]} != -* ]] \
-	   && [ "${COMP_WORDS[i-1]}" != -R ] \
-	   && [ "${COMP_WORDS[i-1]}" != --repository ]; then
-	    cmd="${COMP_WORDS[i]}"
-	    break
+	if [[ ${COMP_WORDS[i]} != -* ]]; then
+	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
+		cmd="${COMP_WORDS[i]}"
+		break
+	    fi
 	fi
     done
 
@@ -80,10 +83,17 @@
 	return
     fi
 
-    if [ "$prev" = -R ] || [ "$prev" = --repository ]; then
-        COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
-	return
-    fi
+    # global options
+    case "$prev" in
+	-R|--repository)
+	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
+	    return
+	;;
+	--cwd)
+	    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
+	    return
+	;;
+    esac
 
     if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
 	_hg_commands


More information about the Mercurial mailing list