dotfiles/.config/zsh/functions/sshproxy

24 lines
702 B
Plaintext
Raw Normal View History

2022-04-17 07:00:18 +02:00
#!/usr/bin/env zsh
# Opens SOCKS5 proxy over SSH
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
zmodload zsh/zutil
local -a o_help=()
local -a o_port=()
zparseopts -D -K -- h=o_help -port:=o_port
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) "usage: ${0} [-h] <HOST>"
return ${ret}
fi
local host=${1}
local port="1080"
[[ ${#o_port} -eq 2 ]] && port=${o_port[2]}
print -P "%F{12}starting SOCKS5 proxy over SSH tunnel to" \
2022-04-17 07:12:12 +02:00
"%F{13}${host}%f %F{12}on%f %F{13}[::1]:${port}%f %F{12}…%f"
print -P "%F{12}curl environment variable:%f" \
2022-04-17 07:00:18 +02:00
"%F{13}ALL_PROXY='socks5://[::1]:${port}'%f"
ssh -D "[::1]:${port}" -N -T ${host}