Skip to content
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
208 changes: 208 additions & 0 deletions completions/_protonvpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#compdef protonvpn
# Zsh completion for protonvpn
# Place this file in a directory listed in $fpath (e.g. /usr/share/zsh/site-functions/)

_protonvpn_toggle_values() {
local -a values
values=(
'on:Enable'
'off:Disable'
)
_describe -t values 'value' values
}

_protonvpn_config_set_custom_dns() {
_arguments \
'1:state:(on off)' \
'--dns[Comma-separated DNS server IPs]:dns IPs: '
}

_protonvpn_config_set() {
local state line
typeset -A opt_args

_arguments -C \
'1:setting:->setting' \
'*::arg:->args'

case $state in
setting)
local -a settings
settings=(
'netshield:Ad-blocking and malware protection'
'kill-switch:Block internet if VPN drops'
'port-forwarding:Port forwarding for P2P'
'custom-dns:Custom DNS servers'
'vpn-accelerator:Performance optimization'
'moderate-nat:NAT type for gaming/P2P'
'ipv6:IPv6 support'
'anonymous-crash-reports:Anonymous crash reporting'
)
_describe -t settings 'setting' settings
;;
args)
case $line[1] in
netshield)
local -a values
values=(
'off:Disable NetShield'
'malware-only:Block malware domains'
'malware-ads-trackers:Block malware, ads, and trackers'
)
_describe -t values 'mode' values
;;
kill-switch)
local -a values
values=(
'off:Disable Kill Switch'
'standard:Block internet if VPN drops'
)
_describe -t values 'mode' values
;;
custom-dns)
_protonvpn_config_set_custom_dns
;;
vpn-accelerator|moderate-nat|ipv6|anonymous-crash-reports|port-forwarding)
_protonvpn_toggle_values
;;
esac
;;
esac
}

_protonvpn_config() {
local state line
typeset -A opt_args

_arguments -C \
'1:subcommand:->subcmd' \
'*::arg:->args'

case $state in
subcmd)
local -a subcommands
subcommands=(
'list:Show current configuration'
'set:Change a setting'
)
_describe -t subcommands 'config subcommand' subcommands
;;
args)
case $line[1] in
set)
_protonvpn_config_set
;;
list)
_message 'no more arguments'
;;
esac
;;
esac
}

_protonvpn_connect() {
_arguments \
'1::server name: ' \
'--country[Connect to country (code or name)]:country: ' \
'--city[Connect to city]:city: ' \
'--p2p[P2P-optimized server]' \
'(-sc --securecore)'{-sc,--securecore}'[Secure Core server]' \
'--tor[Tor over VPN server]' \
'--random[Random server]' \
'(-h --help)'{-h,--help}'[Show help]'
}

_protonvpn_countries() {
local state line
typeset -A opt_args

_arguments -C \
'1:subcommand:->subcmd'

case $state in
subcmd)
local -a subcommands
subcommands=('list:List all countries')
_describe -t subcommands 'countries subcommand' subcommands
;;
esac
}

_protonvpn_cities() {
local state line
typeset -A opt_args

_arguments -C \
'1:subcommand:->subcmd' \
'*::arg:->args'

case $state in
subcmd)
local -a subcommands
subcommands=('list:List cities in a country')
_describe -t subcommands 'cities subcommand' subcommands
;;
args)
case $line[1] in
list)
_message 'country code or name'
;;
esac
;;
esac
}

_protonvpn() {
local state line
typeset -A opt_args

local -a commands
commands=(
'signin:Sign in to Proton VPN'
'signout:Sign out from Proton VPN'
'info:Display account information'
'connect:Connect to VPN server'
'disconnect:Disconnect from VPN'
'status:Show connection status'
'servers:View available servers'
'countries:Discover countries with servers'
'cities:Discover cities with servers'
'config:Configure VPN settings'
)

_arguments -C \
'(-v --verbose)'{-v,--verbose}'[Show detailed output]' \
'(-h --help)'{-h,--help}'[Show help]' \
'1:command:->command' \
'*::arg:->args'

case $state in
command)
_describe -t commands 'protonvpn command' commands
;;
args)
case $line[1] in
signin)
_message 'username'
;;
signout|info|disconnect|status|servers)
_message 'no more arguments'
;;
connect)
_protonvpn_connect
;;
countries)
_protonvpn_countries
;;
cities)
_protonvpn_cities
;;
config)
_protonvpn_config
;;
esac
;;
esac
}

_protonvpn "$@"
118 changes: 118 additions & 0 deletions completions/protonvpn
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Bash completion for protonvpn
# Source this file or place it in /etc/bash_completion.d/
# Requires: bash-completion (https://github.com/scop/bash-completion)

_protonvpn() {
local cur prev words cword
_init_completion || return

local commands="signin signout info connect disconnect status servers countries cities config"
local config_subcommands="list set"
local config_set_settings="netshield kill-switch port-forwarding custom-dns vpn-accelerator moderate-nat ipv6 anonymous-crash-reports"
local toggle_values="on off"

# Walk the command line to determine the subcommand context
local cmd="" subcmd="" setting=""
local i
for ((i = 1; i < cword; i++)); do
case "${words[i]}" in
-v|--verbose|-h|--help)
continue
;;
signin|signout|info|connect|disconnect|status|servers|countries|cities|config)
cmd="${words[i]}"
;;
list|set)
if [[ "$cmd" == "config" || "$cmd" == "countries" || "$cmd" == "cities" ]]; then
subcmd="${words[i]}"
fi
;;
netshield|kill-switch|port-forwarding|custom-dns|vpn-accelerator|moderate-nat|ipv6|anonymous-crash-reports)
if [[ "$cmd" == "config" && "$subcmd" == "set" ]]; then
setting="${words[i]}"
fi
;;
esac
done

# Complete based on context
case "$cmd" in
"")
# Top-level: complete commands and global options
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-v --verbose -h --help" -- "$cur"))
else
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
fi
;;
signin)
# signin takes a USERNAME argument, no completions
return
;;
signout|info|disconnect|status|servers)
# These commands take no arguments
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --help" -- "$cur"))
fi
;;
connect)
if [[ "$prev" == "--country" || "$prev" == "--city" ]]; then
# These take a value argument; no static completions
return
fi
COMPREPLY=($(compgen -W "--country --city --p2p -sc --securecore --tor --random -h --help" -- "$cur"))
;;
countries)
if [[ -z "$subcmd" ]]; then
COMPREPLY=($(compgen -W "list" -- "$cur"))
fi
;;
cities)
if [[ -z "$subcmd" ]]; then
COMPREPLY=($(compgen -W "list" -- "$cur"))
fi
# cities list takes a COUNTRY argument; no static completions
;;
config)
case "$subcmd" in
"")
COMPREPLY=($(compgen -W "$config_subcommands" -- "$cur"))
;;
list)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --help" -- "$cur"))
fi
;;
set)
if [[ -z "$setting" ]]; then
COMPREPLY=($(compgen -W "$config_set_settings" -- "$cur"))
else
# Complete setting values
case "$setting" in
netshield)
COMPREPLY=($(compgen -W "off malware-only malware-ads-trackers" -- "$cur"))
;;
kill-switch)
COMPREPLY=($(compgen -W "off standard" -- "$cur"))
;;
custom-dns)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "--dns -h --help" -- "$cur"))
elif [[ "$prev" == "--dns" ]]; then
return
else
COMPREPLY=($(compgen -W "$toggle_values" -- "$cur"))
fi
;;
vpn-accelerator|moderate-nat|ipv6|anonymous-crash-reports|port-forwarding)
COMPREPLY=($(compgen -W "$toggle_values" -- "$cur"))
;;
esac
fi
;;
esac
;;
esac
}

complete -F _protonvpn protonvpn
Loading