#!/usr/bin/env bash # bash completion for sudo(8) # Adapted for doas # https://github.com/scop/bash-completion/blob/730368b35aeb7f9b7eec62ff0e19b1bd8b385961/completions/sudo _sudo() { local cur prev words cword split _init_completion -s || return local i mode=normal [[ $mode == normal ]] && for ((i = 1; i <= cword; i++)); do if [[ ${words[i]} != -* ]]; then local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin local root_command=${words[i]} _command_offset $i return fi [[ ${words[i]} == -@(!(-*)[uC]) ]] && ((i++)) done case "$prev" in -u) COMPREPLY=($(compgen -u -- "$cur")) return ;; esac $split && return if [[ $cur == -* ]]; then COMPREPLY=($( compgen -W '$(_parse_usage "$1")' -- "$cur" )) [[ ${COMPREPLY-} == *= ]] && compopt -o nospace return fi } complete -F _sudo doas