1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-04-05 20:47:08 +08:00
This commit is contained in:
Erfan Ghavam 2026-03-10 06:35:51 -04:00 committed by GitHub
commit e109257dcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,3 +51,62 @@ function ssh_unload_key {
ssh-add -d "$keyfile"
fi
}
############################################################
# Port forwarding
function ssh_port_forward {
if [[ $# -lt 2 ]]; then
echo "Usage: ssh port-forward <local_port>:<remote_port> user@host [ssh options]"
return 1
fi
local ports="$1"
shift
local local_port="${ports%%:*}"
local remote_port="${ports##*:}"
if [[ -z "$local_port" || -z "$remote_port" ]]; then
echo "Invalid port format. Use local_port:remote_port"
return 1
fi
command ssh -N -L "${local_port}:127.0.0.1:${remote_port}" "$@"
}
############################################################
# SSH SOCKS proxy
function ssh_proxy {
local local_port="$1"
if [[ -z "$local_port" ]]; then
echo "Usage: ssh proxy <local_port> user@host [ssh options]"
return 1
fi
shift
if [[ -z "$local_port" || "$local_port" != <-> ]]; then
echo "Invalid port. Use a numeric local port."
return 1
fi
if [[ $# -lt 1 ]]; then
echo "Usage: ssh proxy local_port user@host [ssh options]"
return 1
fi
command ssh -D "${local_port}" -N "$@"
}
############################################################
# Configure ssh command to support custom subcommands
function ssh {
case "$1" in
port-forward|pf)
shift
ssh_port_forward "$@"
return $?
;;
proxy|px)
shift
ssh_proxy "$@"
return $?
;;
*)
command ssh "$@"
;;
esac
}