monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] bash completion


From: Olivier Andrieu
Subject: [Monotone-devel] bash completion
Date: Wed, 09 Jun 2004 02:05:27 +0200 (CEST)

Hi,

I tried to implement bash completion for monotone. Here's the
result. It seems to be working all right for me.

-- 
   Olivier
# -*- shell-script -*-

# The function _filedir is defined in /etc/bash_completion.
# This is a weaker version, for those who do not have the 
# bash completion package installed. <http://www.caliban.org/bash/>
if ! type _filedir > /dev/null ; then
_filedir() {
    local IFS=$'\t\n' arg
    COMPREPLY=( address@hidden:-} $(compgen ${1:--f} -- $cur) )
}
fi

# Call monotone to complete manifest for file IDs
_monotone_complete() {
  if [ -n "$cur" ] ; then
    COMPREPLY=( address@hidden:-} $(monotone $mono_db complete $1 $cur 2> 
/dev/null) )
  fi
}

_monotone() {
  local cur=${COMP_WORDS[COMP_CWORD]}
  local prev=${COMP_WORDS[COMP_CWORD-1]}
  local mono_db

  for w in address@hidden ; do
    if [[ "$w" == --db=* ]] ; then
      mono_db="$w" ; break
    fi
  done

  case $cur in
    --db=* | --rcfile=* )
      cur="${cur#*=}"
      _filedir
      ;;
    --branch=* )
      COMPREPLY=( $(compgen -W "$(monotone $mono_db list branches)" -- 
${cur#*=} ) )
      ;;
    --key=* )
      COMPREPLY=( $(compgen -W "$(monotone $mono_db list keys |\
                                  sed -n '/\[private 
keys\]/,${/^[0-9a-f]/s/[0-9a-f]* //p}')" -- ${cur#*=} ) )
      ;;
    -* )
      COMPREPLY=( $(compgen -W '--verbose --quiet --help --nostd --norc\
                                --rcfile= --key= --db= --branch= --version' -- 
$cur) ) 
      ;;
    * )
      case $prev in
        db )
          COMPREPLY=( $(compgen -W 'init info version dump load migrate' -- 
$cur ) )
          ;;
        diff | log | approve | disapprove | comment | tag | testresult | cert )
          _monotone_complete manifest
          ;;
        ls | list )
          COMPREPLY=( $(compgen -W 'certs keys branches unknown ignored 
missing' -- $cur ) )
          ;;
        co | checkout )
          _filedir -d
          _monotone_complete manifest
          ;;
        cvs_import | add | drop | rename | revert )
          _filedir
          ;;
        cat )
          COMPREPLY=( $(compgen -W 'file manifest' -- $cur) )
          ;;
        push | pull | serve | sync )
          COMPREPLY=( $(compgen -A hostname -- $cur) )
          ;;
        * )
          if (( $COMP_CWORD >= 2 )) ; then
            local prev2=${COMP_WORDS[COMP_CWORD-2]}
            case $prev2 in
              diff | approve | disapprove )
                _monotone_complete manifest
                ;;
              co | checkout )
                _filedir -d
                ;;
              cat )
                _monotone_complete $prev
                ;;
              list )
                if [ $prev == certs ] ; then
                    _monotone_complete manifest 
                    _monotone_complete file
                fi
                ;;
              push | pull | serve | sync )
                COMPREPLY=( $(compgen -W "$(monotone $mono_db list branches)" 
-- $cur) )
                ;;
              * )
                unset prev2
                ;;
            esac
          fi
          if [ -z "$prev2" ] ; then
            COMPREPLY=( $(compgen -W 'approve comment disapprove tag testresult 
\
                                      db agraph debug \
                                      complete diff list log ls status \
                                      cert genkey vcheck pull push reindex 
serve sync \
                                      fcerts fdata fdelta mcerts mdata mdelta 
privkey pubkey read \
                                      cvs_import rcs_import \
                                      bump cat checkout co fload fmerge heads 
merge propagate \
                                      add commit drop rename revert update' -- 
$cur) )
          fi
          ;;
      esac
      ;;
  esac
  return 0
}

complete -F _monotone -o default monotone

reply via email to

[Prev in Thread] Current Thread [Next in Thread]