-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(doas): new completion #766
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ bashcomp_DATA = 2to3 \ | |
dmypy \ | ||
dnssec-keygen \ | ||
dnsspoof \ | ||
doas \ | ||
dot \ | ||
dpkg \ | ||
dpkg-source \ | ||
|
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 | ||
return | ||
fi | ||
[[ ${words[i]} == -@(!(-*)[uCLs]) ]] && | ||
((i++)) | ||
done | ||
|
||
case "$prev" in | ||
-!(-*)u) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above; I simply use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will fail to match the case where |
||
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 |
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(" ") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ display | |
dmesg | ||
dmypy | ||
dnsspoof | ||
doas | ||
dpkg | ||
dpkg-deb | ||
dpkg-query | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between what you wrote and my suggestion below? They both seem to work, but my suggestion seems simpler.