Skip to content

Commit

Permalink
Add bash-completion support
Browse files Browse the repository at this point in the history
Loosely based on bash-completion's sudo support
  • Loading branch information
FintasticMan committed Dec 23, 2021
1 parent 9a25a6d commit fe764f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 7 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
PROG= doas
MAN= doas.1 doas.conf.5
PROG= doas
MAN= doas.1 doas.conf.5
COMPLETION= doas.completion

SRCS= parse.y doas.c env.c
SRCS= parse.y doas.c env.c

include config.mk

Expand All @@ -19,17 +20,20 @@ install: ${PROG} ${MAN}
mkdir -p -m 0755 ${DESTDIR}${BINDIR}
mkdir -p -m 0755 ${DESTDIR}${MANDIR}/man1
mkdir -p -m 0755 ${DESTDIR}${MANDIR}/man5
mkdir -p -m 0755 ${DESTDIR}/share/bash-completion/completions
cp -f ${PROG} ${DESTDIR}${BINDIR}
chown ${BINOWN}:${BINGRP} ${DESTDIR}${BINDIR}/${PROG}
chmod ${BINMODE} ${DESTDIR}${BINDIR}/${PROG}
cp -f doas.1 ${DESTDIR}${MANDIR}/man1
cp -f doas.conf.5 ${DESTDIR}${MANDIR}/man5
cp -f doas.completion ${DESTDIR}/share/bash-completion/completions/doas

uninstall:
rm -f ${DESTDIR}${BINDIR}/${PROG}
rm -f ${DESTDIR}${PAMDIR}/doas
rm -f ${DESTDIR}${MANDIR}/man1/doas.1
rm -f ${DESTDIR}${MANDIR}/man5/doas.conf.5
rm -f ${DESTDIR}/share/bash-completion/completions/doas

clean:
rm -f ${PROG} ${OBJS} ${OBJS:.o=.d} parse.c
Expand Down
19 changes: 19 additions & 0 deletions doas.completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# bash completion for doas(1) -*- shell-script -*-

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

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]} == -u ]] || [[ ${words[i]} == -C ]] && ((i++))
done
} && complete -F _doas doas

# ex: filetype=sh

0 comments on commit fe764f4

Please sign in to comment.