Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ bashcomp_DATA = 2to3 \
dmypy \
dnssec-keygen \
dnsspoof \
doas \
dot \
dpkg \
dpkg-source \
Expand Down
45 changes: 45 additions & 0 deletions completions/doas
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# doas(1) completion -*- shell-script -*-

_comp_cmd_doas()
{
local cur prev words cword split
_init_completion -s || return

local i

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a similar way to_comp_root_command() (defined in bash_completion), I think we want to enable the completion as if the current user has root privilege.

Suggested change
_command_offset $i
local _comp_root_command=1
_command_offset $i

return
fi
[[ ${words[i]} == -@(!(-*)[uCLs]) ]] &&
((i++))
done

case "$prev" in
-!(-*)u)
COMPREPLY=($(compgen -u -- "$cur"))
return
;;
-!(-*)C)
_filedir
return
;;
-!(-*)[Ls])
return
;;
esac

$split && return

if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_usage "$1")' -- "$cur"))
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
} &&
complete -F _comp_cmd_doas doas

# ex: filetype=sh
1 change: 1 addition & 0 deletions test/t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ EXTRA_DIST = \
test_dmypy.py \
test_dnssec_keygen.py \
test_dnsspoof.py \
test_doas.py \
test_dot.py \
test_dpkg.py \
test_dpkg_deb.py \
Expand Down
17 changes: 17 additions & 0 deletions test/t/test_doas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest


class TestDoas:
@pytest.mark.complete("doas -", require_cmd=True)
def test_1(self, completion):
assert completion

@pytest.mark.complete("doas cd foo", cwd="shared/default")
def test_2(self, completion):
assert completion == ".d/"
assert not completion.endswith(" ")

@pytest.mark.complete("doas sh share")
def test_3(self, completion):
assert completion == "d/"
assert not completion.endswith(" ")
1 change: 1 addition & 0 deletions test/test-cmd-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ display
dmesg
dmypy
dnsspoof
doas
dpkg
dpkg-deb
dpkg-query
Expand Down