54 lines
1.5 KiB
Bash
54 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) 2025. LUXIM d.o.o., Slovenia - Matjaž Mozetič.
|
|
|
|
_backtunnel_complete() {
|
|
local cur
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
|
compopt -o filenames 2>/dev/null
|
|
mapfile -t COMPREPLY < <(compgen -d -- "${cur}")
|
|
return 0
|
|
fi
|
|
|
|
if [[ ${COMP_CWORD} -eq 2 ]]; then
|
|
mapfile -t COMPREPLY < <(compgen -W "with from" -- "${cur}")
|
|
return 0
|
|
fi
|
|
|
|
if [[ ${COMP_CWORD} -eq 4 && "${COMP_WORDS[2]}" == "with" ]]; then
|
|
mapfile -t COMPREPLY < <(compgen -W "for" -- "${cur}")
|
|
return 0
|
|
fi
|
|
|
|
if [[ ${COMP_CWORD} -eq 5 && "${COMP_WORDS[2]}" == "with" && "${COMP_WORDS[4]}" == "for" ]]; then
|
|
mapfile -t COMPREPLY < <(compgen -W "10m 30m 1h 2h 6h 12h 1d 2d" -- "${cur}")
|
|
return 0
|
|
fi
|
|
|
|
if [[ "${COMP_WORDS[2]}" == "from" ]]; then
|
|
COMPREPLY=()
|
|
return 0
|
|
fi
|
|
|
|
# backtunnel-share: after positionals, propose flags incl. invite
|
|
if [[ ${COMP_WORDS[0]} == backtunnel-share && ${COMP_CWORD} -ge 5 ]]; then
|
|
local opts="-p --tunnel-port -l --local-ssh-port -i --invite --invite-mount --invite-file --qr -h --help"
|
|
mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
|
|
return 0
|
|
fi
|
|
|
|
# backtunnel-access: after positionals, propose its flags
|
|
if [[ ${COMP_WORDS[0]} == backtunnel-access && ${COMP_CWORD} -ge 3 ]]; then
|
|
local opts="-p --port -m --mount-point -h --help"
|
|
mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
|
|
return 0
|
|
fi
|
|
|
|
COMPREPLY=()
|
|
}
|
|
|
|
complete -F _backtunnel_complete backtunnel-share
|
|
complete -F _backtunnel_complete backtunnel-access
|