Skip to content
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

Add bash-completion support #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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}${COMPDIR}/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}${COMPDIR}/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}${COMPDIR}/completions/doas

clean:
rm -f ${PROG} ${OBJS} ${OBJS:.o=.d} parse.c
Expand Down
4 changes: 4 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ usage: configure [options]
--bindir=DIR user executables [PREFIX/bin]
--datadir=DIR architecture-independent data files [PREFIX/share]
--mandir=DIR manual pages [DATADIR/man]
--compdir=DIR bash completions [DATADIR/bash-completion]
--sysconfdir=DIR directory for configuration files [/etc]

--build=build-alias a cpu-vendor-opsys for the system where the application will be built
Expand Down Expand Up @@ -50,6 +51,7 @@ for x; do
--bindir) BINDIR=$var ;;
--datadir) SHAREDIR=$var ;;
--mandir) MANDIR=$var ;;
--compdir) COMPDIR=$var ;;
--sysconfdir) SYSCONFDIR=$var ;;
--build) BUILD=$var ;;
--host) HOST=$var ;;
Expand Down Expand Up @@ -131,6 +133,7 @@ esac
: ${BINDIR:=${PREFIX}/bin}
: ${SHAREDIR:=${PREFIX}/share}
: ${MANDIR:=${SHAREDIR}/man}
: ${COMPDIR:=${SHAREDIR}/bash-completion}
: ${SYSCONFDIR:=/etc}
: ${BINMODE:=4755}
: ${BINOWN:=root}
Expand All @@ -142,6 +145,7 @@ EPREFIX ?= ${EPREFIX}
BINDIR ?= ${BINDIR}
SHAREDIR ?= ${SHAREDIR}
MANDIR ?= ${MANDIR}
COMPDIR ?= ${COMPDIR}
SYSCONFDIR?= ${SYSCONFDIR}
BINMODE ?= ${BINMODE}
BINOWN ?= ${BINOWN}
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|C) ]] && ((i++))
done
} && complete -F _doas doas

# ex: filetype=sh