Skip to content

Commit a30448c

Browse files
committed
Allow the ssh forwarding functions to take multiple ports
1 parent 4fadf66 commit a30448c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎default/bash/functions‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,19 @@ img2png() {
9090

9191
# SSH Port Forwarding Functions
9292
fip() {
93-
[[ -z "$1" || -z "$2" ]] && echo "Usage: fip <port> <host>" && return 1
94-
ssh -f -N -L "$1:localhost:$1" "$2" && echo "Forwarding localhost:$1 -> $2:$1"
93+
[[ $# -lt 2 ]] && echo "Usage: fip <host> <port1> [port2] ..." && return 1
94+
local host="$1"
95+
shift
96+
for port in "$@"; do
97+
ssh -f -N -L "$port:localhost:$port" "$host" && echo "Forwarding localhost:$port -> $host:$port"
98+
done
9599
}
96100

97101
dip() {
98-
[[ -z "$1" ]] && echo "Usage: dip <port>" && return 1
99-
pkill -f "ssh.*-L $1:localhost:$1" && echo "Stopped forwarding port $1" || echo "No forwarding on port $1"
102+
[[ $# -eq 0 ]] && echo "Usage: dip <port1> [port2] ..." && return 1
103+
for port in "$@"; do
104+
pkill -f "ssh.*-L $port:localhost:$port" && echo "Stopped forwarding port $port" || echo "No forwarding on port $port"
105+
done
100106
}
101107

102108
lip() {

0 commit comments

Comments
 (0)