Bash completion
Useful completion function if you have sudo to a number of users with a small number of commands.
<geshi lang="bash">
_sudo()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "${prev}" in
-u)
COMPREPLY=( $(compgen -W "$(sudo -l | grep "^ " | cut -c6-13 | sort | uniq )" -- ${cur}) )
return 0;
;;
*)
;;
esac
if [ $COMP_CWORD -eq 3 ]; then
COMPREPLY=( $(compgen -W "$(sudo -l | grep "\(${prev}\)" | cut -c16- | tr ',' ' ' )" -- ${cur}) )
return 0;
fi
}
complete -F _sudo sudo </geshi>