Skip to content

Commit

Permalink
vpnc: Improve config completions
Browse files Browse the repository at this point in the history
Load completions in /etc/vpnc by *.conf name, avoiding inclusion of
non-conf files from there as completions (e.g. vpnc-script). Also
support loading completions from explicit filenames elsewhere.
  • Loading branch information
scop committed Sep 11, 2017
1 parent 53feba3 commit c695083
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion completions/vpnc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ _vpnc()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" --long-help )' \
-- "$cur" ) )
elif [[ "$cur" == */* ]]; then
# explicit filename
_filedir conf
else
COMPREPLY=( $( compgen -W '$( command ls /etc/vpnc )' -- "$cur" ) )
# config name, /etc/vpnc/<name>.conf
local IFS=$' \t\n' reset=$(shopt -p nullglob); shopt -s nullglob
local -a configs=( /etc/vpnc/*.conf )
configs=( "${configs[@]##*/}" )
configs=( "${configs[@]%.conf}" )
$reset
IFS=$'\n'
compopt -o filenames
COMPREPLY=( $( compgen -W '${configs[@]}' -- "$cur" ) )
fi
} &&
complete -F _vpnc vpnc
Expand Down

0 comments on commit c695083

Please sign in to comment.