main/bash-completion: add doas completion

Upstream is very slowly and didn't merge the PR since June 2024.

Closes https://gitlab.alpinelinux.org/alpine/aports/-/issues/16453
This commit is contained in:
fossdd 2025-01-11 17:45:37 +01:00
parent 357d45b156
commit 6ccfd5d249
2 changed files with 120 additions and 1 deletions

View File

@ -13,7 +13,9 @@ depends="bash"
makedepends="autoconf automake bc grep iputils musl-utils procps psmisc sed usbutils"
checkdepends="py3-pexpect py3-pytest"
subpackages="$pkgname-dev $pkgname-doc"
source="https://github.com/scop/bash-completion/releases/download/$pkgver/bash-completion-$pkgver.tar.xz"
source="https://github.com/scop/bash-completion/releases/download/$pkgver/bash-completion-$pkgver.tar.xz
add-doas-completion.patch
"
# Provided by other packages
_conflicting="
@ -96,4 +98,5 @@ package() {
sha512sums="
3711d6cb53cedff94efca0325479ac73f40b536fce250dbcc18ef120a8d0d2248f086ca26e245d163e6058d1b1087d57ced041317163d0e25592d6cb7acbc102 bash-completion-2.16.0.tar.xz
39f49a43a660049721a80bccb6a6cf63916e605ab9d33b5bbadf99256650f5ed2e0caa38b22d23b79b9cd3975cb297f7b5d9e12353202eecc01253dd9780002a add-doas-completion.patch
"

View File

@ -0,0 +1,116 @@
Patch-Source: https://github.com/scop/bash-completion/pull/766
(but test/test-cmd-list.txt removed)
---
From 2d7a7f0415158f0e5733bb259c36550fa673c3c2 Mon Sep 17 00:00:00 2001
From: archetype <burchakov.oleg@gmail.com>
Date: Sun, 26 Jun 2022 21:18:30 +0300
Subject: [PATCH] feat(doas): new completion
---
completions/Makefile.am | 1 +
completions/doas | 45 +++++++++++++++++++++++++++++++++++++++++
test/t/Makefile.am | 1 +
test/t/test_doas.py | 17 ++++++++++++++++
test/test-cmd-list.txt | 1 +
5 files changed, 65 insertions(+)
create mode 100644 completions/doas
create mode 100644 test/t/test_doas.py
diff --git a/completions/Makefile.am b/completions/Makefile.am
index 2a7a5b3adf2..f5a1829fbf2 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -86,6 +86,7 @@ bashcomp_DATA = 2to3 \
dmypy \
dnssec-keygen \
dnsspoof \
+ doas \
dot \
dpkg \
dpkg-source \
diff --git a/completions/doas b/completions/doas
new file mode 100644
index 00000000000..1b5abc64b19
--- /dev/null
+++ b/completions/doas
@@ -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)
+ 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
diff --git a/test/t/Makefile.am b/test/t/Makefile.am
index 8b6dcdcbc4f..b8be503abde 100644
--- a/test/t/Makefile.am
+++ b/test/t/Makefile.am
@@ -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 \
diff --git a/test/t/test_doas.py b/test/t/test_doas.py
new file mode 100644
index 00000000000..a8039c58608
--- /dev/null
+++ b/test/t/test_doas.py
@@ -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(" ")