# HG changeset patch # User Alexis S. L. Carvalho # Date 2005-08-29 18:37:07 # Node ID 10b4f2a5ce17fe88152327d127f416d1292779d4 # Parent 4ee09418c8e5af86596fd6d080728501be5f6b78 teach bash_completion about --cwd diff --git a/contrib/bash_completion b/contrib/bash_completion --- a/contrib/bash_completion +++ b/contrib/bash_completion @@ -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