[Bash-completion-devel] new completion for "upstart" for review

James Hunt james.hunt at canonical.com
Thu Nov 25 11:40:30 UTC 2010


Hi All,

Attached is a new bash completion I have written for the "upstart"
init replacement (http://upstart.ubuntu.com).

Please could this be added to the review queue.

Thank you in advance.

-- 
Kind regards,

James Hunt
______________________________________________________________________
Ubuntu Foundations Team, Canonical.
-------------- next part --------------
# bash-completion for the upstart event-based init replacement.
# We don't provide completion for 'init' itself for obvious reasons.
have initctl &&
_upstart_conf_events()
{
  initctl list|awk '{print $1}'
} &&
_upstart_named_events()
{
  (cd /etc/init && grep '^emits ' *.conf|sed 's/^emits //g')
} &&
_upstart_events()
{
  (_upstart_conf_events;_upstart_named_events)|tr ' ' '\n'|sort -u
} &&
_upstart_startable_events()
{
  initctl list|cut -d\, -f1|awk '$2 == "stop/waiting" {print $1}'
} &&
_upstart_stoppable_events()
{
  initctl list|cut -d\, -f1|awk '$2 == "start/running" {print $1}'
} &&
_upstart_initctl()
{
  _get_comp_words_by_ref cur prev

  COMPREPLY=()

  case "$prev" in

    start)
      COMPREPLY=( $(compgen -W "$(_upstart_startable_events)" -- ${cur}) )
      return 0
    ;;

    stop)
      COMPREPLY=( $(compgen -W "$(_upstart_stoppable_events)" -- ${cur}) )
      return 0
    ;;

    emit)
      COMPREPLY=( $(compgen -W "$(_upstart_events)" -- ${cur}) )
      return 0
    ;;

    reload|restart|status)
      COMPREPLY=( $(compgen -W "$(_upstart_conf_events)" -- ${cur}) )
      return 0
    ;;

    --help|--version)
      COMPREPLY=()
      return 0
    ;;

  esac

  opts="--help --version -q --quiet -v --verbose --system --dest="
  cmds=$(initctl help|grep "^  [^ ]"|awk '{print $1}')

  COMPREPLY=( $(compgen -W "${opts} ${cmds}" -- ${cur}) )

} && complete -F _upstart_initctl initctl

have start &&
_upstart_start()
{
  COMPREPLY=()
  _get_comp_words_by_ref cur prev

  opts="--help --version -q --quiet -v --verbose --system --dest= \
        -n --no-wait"

  case "$prev" in
    --help|--version)
      COMPREPLY=()
      return 0
    ;;
  esac

  COMPREPLY=( $(compgen -W "$opts $(_upstart_startable_events)" -- ${cur}) )
  return 0
} && complete -F _upstart_start start

have stop &&
_upstart_stop()
{
  COMPREPLY=()
  _get_comp_words_by_ref cur prev

  opts="--help --version -q --quiet -v --verbose --system --dest= \
        -n --no-wait"

  case "$prev" in
    --help|--version)
      COMPREPLY=()
      return 0
    ;;
  esac

  COMPREPLY=( $(compgen -W "$opts $(_upstart_stoppable_events)" -- ${cur}) )
  return 0
} && complete -F _upstart_stop stop

have restart &&
_upstart_restart()
{
  COMPREPLY=()
  _get_comp_words_by_ref cur prev

  opts="--help --version -q --quiet -v --verbose --system --dest= \
        -n --no-wait"

  case "$prev" in
    --help|--version)
      COMPREPLY=()
      return 0
    ;;
  esac

  COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) )
  return 0

} && complete -F _upstart_restart restart

have status &&
_upstart_status()
{
  COMPREPLY=()
  _get_comp_words_by_ref cur prev

  opts="--help --version -q --quiet -v --verbose --system --dest="

  case "$prev" in
    --help|--version)
      COMPREPLY=()
      return 0
    ;;
  esac

  COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) )
  return 0

} && complete -F _upstart_status status

have reload &&
_upstart_reload()
{
  COMPREPLY=()
  _get_comp_words_by_ref cur prev

  opts="--help --version -q --quiet -v --verbose --system --dest="

  case "$prev" in
    --help|--version)
      COMPREPLY=()
      return 0
    ;;
  esac

  COMPREPLY=( $(compgen -W "$opts $(_upstart_events)" -- ${cur}) )
  return 0

} && complete -F _upstart_reload reload
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20101125/b0cafa8b/attachment.pgp>


More information about the Bash-completion-devel mailing list