Skip to content

Commit ad5ec9a

Browse files
authored
Merge pull request #766 from aarchetype/doas
feat(doas): new completion
2 parents 8baa60b + a705713 commit ad5ec9a

5 files changed

Lines changed: 66 additions & 0 deletions

File tree

completions-core/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ cross_platform = 2to3.bash \
8282
dmypy.bash \
8383
dnssec-keygen.bash \
8484
dnsspoof.bash \
85+
doas.bash \
8586
dot.bash \
8687
dpkg.bash \
8788
dpkg-source.bash \

completions-core/doas.bash

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# doas(1) completion
2+
3+
_comp_cmd_doas()
4+
{
5+
local cur prev words cword was_split comp_args
6+
_comp_initialize -s -- "$@" || return
7+
8+
local noargopts='!(-*|*[uCLs]*)'
9+
10+
local i
11+
for ((i = 1; i <= cword; i++)); do
12+
if [[ ${words[i]} != -* ]]; then
13+
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
14+
local root_command=${words[i]}
15+
local _comp_root_command=$1
16+
_comp_command_offset "$i"
17+
return
18+
fi
19+
[[ ${words[i]} == -@(${noargopts}[uCLs]) ]] &&
20+
((i++))
21+
done
22+
23+
# shellcheck disable=SC2254 # glob $noargopts should not be quoted
24+
case $prev in
25+
-${noargopts}u)
26+
_comp_compgen -- -u
27+
return
28+
;;
29+
-${noargopts}C)
30+
_comp_compgen_filedir
31+
return
32+
;;
33+
-${noargopts}[Ls])
34+
return
35+
;;
36+
esac
37+
38+
[[ $was_split ]] && return
39+
40+
if [[ $cur == -* ]]; then
41+
_comp_compgen_usage
42+
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
43+
return
44+
fi
45+
} &&
46+
complete -F _comp_cmd_doas doas

test/t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ EXTRA_DIST = \
140140
test_dmypy.py \
141141
test_dnssec_keygen.py \
142142
test_dnsspoof.py \
143+
test_doas.py \
143144
test_dot.py \
144145
test_dpkg.py \
145146
test_dpkg_deb.py \

test/t/test_doas.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
4+
class TestDoas:
5+
@pytest.mark.complete("doas -", require_cmd=True)
6+
def test_1(self, completion):
7+
assert completion
8+
9+
@pytest.mark.complete("doas cd foo", cwd="shared/default")
10+
def test_2(self, completion):
11+
assert completion == ".d/"
12+
assert not completion.endswith(" ")
13+
14+
@pytest.mark.complete("doas sh share")
15+
def test_3(self, completion):
16+
assert completion == "d/"
17+
assert not completion.endswith(" ")

test/test-cmd-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ display
7979
dmesg
8080
dmypy
8181
dnsspoof
82+
doas
8283
dpkg
8384
dpkg-deb
8485
dpkg-query

0 commit comments

Comments
 (0)