1
0
2025-08-25 02:55:30 +02:00

49 lines
1.2 KiB
Bash

#!/bin/bash
_mtm-ssh-vpn() {
# shellcheck disable=SC2034
local cur prev words cword args
_init_completion || return
local -r CNF_ARGS="--help"
local -r CMD_ARGS="status connect disconnect disconnect-all"
local -r PROFILE_DIR=~/.config/mtm-ssh-proxy
local -r TMP_DIR="/tmp/mtm-ssh-proxy-${USER}/vpn"
if [[ ${COMP_WORDS[*]} == *"--help"* ]]; then
return
fi
args=${CMD_ARGS}
for arg in ${CNF_ARGS}; do
if [[ ${COMP_WORDS[*]} != *"${arg}"* ]]; then
args+=" ${arg}"
fi
done
for arg in ${CMD_ARGS}; do
if [[ ${COMP_WORDS[*]} == *" ${arg} "* ]]; then
args=""
fi
done
case $prev in
--help | status | disconnect_all) return;;
connect)
local -r PROFILELIST=$(\ls "${PROFILE_DIR}")
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${PROFILELIST}" -- "${COMP_WORDS[COMP_CWORD]}"))
return
;;
disconnect)
local -r PROFILELIST=$(\ls "${TMP_DIR}")
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${PROFILELIST}" -- "${COMP_WORDS[COMP_CWORD]}"))
return
;;
*)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${args}" -- "${COMP_WORDS[COMP_CWORD]}"))
return
;;
esac
} && complete -F _mtm-ssh-vpn mtm-ssh-vpn