Skip to content
Merged
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-core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ cross_platform = 2to3.bash \
dmypy.bash \
dnssec-keygen.bash \
dnsspoof.bash \
doas.bash \
dot.bash \
dpkg.bash \
dpkg-source.bash \
Expand Down
46 changes: 46 additions & 0 deletions completions-core/doas.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# doas(1) completion

_comp_cmd_doas()
{
local cur prev words cword was_split comp_args
_comp_initialize -s -- "$@" || return

local noargopts='!(-*|*[uCLs]*)'

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]}
local _comp_root_command=$1
_comp_command_offset "$i"
return
fi
[[ ${words[i]} == -@(${noargopts}[uCLs]) ]] &&
((i++))
done

# shellcheck disable=SC2254 # glob $noargopts should not be quoted
case $prev in
-${noargopts}u)
_comp_compgen -- -u
return
;;
-${noargopts}C)
_comp_compgen_filedir
return
;;
-${noargopts}[Ls])
return
;;
esac

[[ $was_split ]] && return

if [[ $cur == -* ]]; then
_comp_compgen_usage
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
} &&
complete -F _comp_cmd_doas doas
1 change: 1 addition & 0 deletions test/t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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 @@ -79,6 +79,7 @@ display
dmesg
dmypy
dnsspoof
doas
dpkg
dpkg-deb
dpkg-query
Expand Down