[Nix-dev] upstart / saving some keystrokes

Marc Weber marco-oweber at gmx.de
Fri Sep 18 23:13:22 CEST 2009


I'm very lazy. I'd like to get even lazier by adding bash upstart
completion.

I found a completion script on a mailinglist and stripped it:

  ==========
  _upstart_comp_list(){
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    if [ $COMP_CWORD -eq 1 ]; then
        COMPREPLY=( $(compgen -o filenames -W "$@" $cur) )
    fi
  }

  _upstart_complete() { _upstart_comp_list "$(initctl list 2>&1 | grep -E
  "$1" | cut -f2 -d ' ')"; }

  _waiting(){ _upstart_complete "(waiting|instance)"; }
  _running(){ _upstart_complete "(running|instance)"; }
  _jobs(){ _upstart_comp_list "$(ls -1 /etc/event.d 2> /dev/null)"; }

  complete -F _jobs status
  complete -F _waiting start
  complete -F _running stop
  complete -F _running restart
  ========

It saves a lot of typing.
It'll be installed to $out/etc/bash-completion.d so that you can source
it.

However its that useful (even Luis agrees :) that I'd like to enable it
by default.

Which is the best way to do this?

Add to /etc/bashrc :
if id == 0 then source_completion_script ?

Because using completion as non root doesn't make sense, does it?

Should a completion script use sudo while completing?

The ls -1 /etc/event.d/ implementation for status should work for
everone.
However sudo status <tab> doesn't show up the list.
So maybe I'm missing the correct sudo completion functions?

How do you feel about this?

Sincerly

Marc Weber



More information about the nix-dev mailing list