diff --git a/.config/zsh/completions/_sshproxy b/.config/zsh/completions/_sshproxy new file mode 100644 index 0000000..715690e --- /dev/null +++ b/.config/zsh/completions/_sshproxy @@ -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: diff --git a/.config/zsh/functions/sshproxy b/.config/zsh/functions/sshproxy new file mode 100755 index 0000000..d123786 --- /dev/null +++ b/.config/zsh/functions/sshproxy @@ -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] " + 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}