contrib/bash_completion
changeset 1308 2073e5a71008
parent 1263 bc1815cf89a7
child 1311 db8bebb08f8f
equal deleted inserted replaced
1285:1546c2aa6b30 1308:2073e5a71008
     1 #!/bin/bash
     1 #!/bin/bash
     2 
     2 
     3 _hg_commands()
     3 _hg_commands()
     4 {
     4 {
     5     local commands="$(hg -v help | sed -e '1,/^list of commands:/d' \
     5     local commands="$(hg -v help | sed -e '1,/^list of commands:/d' \
     6                                        -e '/^global options:/,$d' \
     6 				       -e '/^global options:/,$d' \
     7 				       -e '/^ [^ ]/!d; s/[,:]//g;')"
     7 				       -e '/^ [^ ]/!d; s/[,:]//g;')"
     8     
     8 
     9     # hide debug commands from users, but complete them if 
     9     # hide debug commands from users, but complete them if
    10     # specifically asked for
    10     # specifically asked for
    11     if [[ "$cur" == de* ]]; then
    11     if [[ "$cur" == de* ]]; then
    12 	commands="$commands debugcheckstate debugstate debugindex"
    12 	commands="$commands debugcheckstate debugstate debugindex"
    13 	commands="$commands debugindexdot debugwalk debugdata"
    13 	commands="$commands debugindexdot debugwalk debugdata"
    14 	commands="$commands debugancestor debugconfig debugrename"
    14 	commands="$commands debugancestor debugconfig debugrename"
    60 
    60 
    61     COMPREPLY=()
    61     COMPREPLY=()
    62     cur="$2"
    62     cur="$2"
    63     prev="$3"
    63     prev="$3"
    64 
    64 
    65     # searching for the command 
    65     # searching for the command
    66     # (first non-option argument that doesn't follow a global option that
    66     # (first non-option argument that doesn't follow a global option that
    67     #  receives an argument)
    67     #  receives an argument)
    68     for (( i=1; $i<=$COMP_CWORD; i++ )); do
    68     for (( i=1; $i<=$COMP_CWORD; i++ )); do
    69 	if [[ ${COMP_WORDS[i]} != -* ]]; then
    69 	if [[ ${COMP_WORDS[i]} != -* ]]; then
    70 	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
    70 	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
   158 		_hg_tags
   158 		_hg_tags
   159 	    else
   159 	    else
   160 		COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
   160 		COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
   161 	    fi
   161 	    fi
   162 	;;
   162 	;;
   163 	*) 
   163 	*)
   164             COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
   164             COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
   165 	;;
   165 	;;
   166     esac
   166     esac
   167 
   167 
   168 }
   168 }