Skip to content

Commit 7e05e10

Browse files
authored
Add autocomplete script
1 parent 783cc0f commit 7e05e10

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

autocomplete/crew-sudo.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# bash completion for crew-sudo command
2+
3+
function _crew-sudo () {
4+
# available options
5+
local avail_opts=(--bashrc --foreground --replace)
6+
7+
# available commands
8+
local cmds=(client daemon stop-daemon)
9+
10+
# parameter that trigger this function
11+
local current="${COMP_WORDS[COMP_CWORD]}"
12+
13+
if [[ "${current:0:1}" == '-' ]]; then
14+
# match ${current} with available option list if ${current} start with '-'
15+
# save result to $COMPREPLY variable
16+
COMPREPLY=( $(compgen -W "${avail_opts[*]}" -- "${current}") )
17+
elif [[ ${COMP_CWORD} == 1 ]]; then
18+
# match ${current} with command list if ${current} is the first argument
19+
COMPREPLY=( $(compgen -W "${cmds[*]}" -- "${current}") )
20+
else
21+
return 1
22+
fi
23+
}
24+
25+
# register this function as completion function for crew-sudo command
26+
complete -F _crew-sudo crew-sudo

install.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ if [ ${EUID} != 0 ] && [ ! -w ${INSTALL_PREFIX} ]; then
55
exit 1
66
fi
77

8-
INSTALL_PREFIX="${CREW_PREFIX:-/usr/local}"
8+
if [ -z "${CREW_DEST_PREFIX}" ]; then
9+
INSTALL_PREFIX="${CREW_DEST_PREFIX}"
10+
else
11+
: "${INSTALL_PREFIX:=/usr/local}"
12+
fi
913

1014
cp -r . ${INSTALL_PREFIX}/lib/crew-sudo
1115

12-
ln -s ../lib/crew-sudo/crew-sudo ${INSTALL_PREFIX}/bin/crew-sudo
13-
ln -s ../lib/crew-sudo/crew-sudo ${INSTALL_PREFIX}/bin/sudo
16+
ln -sf ../lib/crew-sudo/crew-sudo ${INSTALL_PREFIX}/bin/crew-sudo
17+
ln -sf ../lib/crew-sudo/crew-sudo ${INSTALL_PREFIX}/bin/sudo
1418

1519
if [ -d ${INSTALL_PREFIX}/etc/env.d ]; then
1620
# installing under chromebrew
17-
ln -s ../lib/crew-sudo/autostart/crew-sudo.sh ${INSTALL_PREFIX}/etc/env.d/crew_sudo
21+
ln -sf ../lib/crew-sudo/autostart/crew-sudo.sh ${INSTALL_PREFIX}/etc/env.d/crew_sudo
22+
ln -sf ../lib/crew-sudo/autocomplete/crew-sudo.sh ${INSTALL_PREFIX}/etc/bash.d/crew_sudo
1823
else
1924
# installing without chromebrew, append the autostart script to bashrc
2025
echo "source ${INSTALL_PREFIX}/lib/crew-sudo/autostart/crew-sudo.sh" > ~/.bashrc

0 commit comments

Comments
 (0)