Add sshproxy()

This commit is contained in:
tastytea 2022-04-17 07:00:18 +02:00
parent 0506b66d91
commit ce31dbea7f
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,9 @@
#compdef sshproxy
_arguments '-h[short help text]' \
'--port[local port]:port:' \
'1:server:_ssh_hosts'
# Local Variables:
# mode: shell-script
# End:

23
.config/zsh/functions/sshproxy Executable file
View File

@ -0,0 +1,23 @@
#!/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" \
"%F{magenta}${host}%f %F{12}on %F{13}[::1]:${port}%f %F{12}…"
print -P "%F{12}curl environment variable:" \
"%F{13}ALL_PROXY='socks5://[::1]:${port}'%f"
ssh -D "[::1]:${port}" -N -T ${host}