58 lines
880 B
Bash
Executable file
58 lines
880 B
Bash
Executable file
#!/bin/bash -e
|
|
|
|
shopt -s expand_aliases
|
|
[[ $TERM = xterm-kitty ]] && alias ssh='kitty +kitten ssh'
|
|
|
|
# Variables
|
|
ssh=ssh
|
|
declare -a args
|
|
|
|
# Display the usage
|
|
function usage {
|
|
cat << EOF
|
|
Usage: $(basename "$0") SSH_HOST LOCAL_PORT DISTANT_PORT [TARGET] [-- SSH_OPTIONS]
|
|
EOF
|
|
}
|
|
|
|
function error {
|
|
>&2 usage
|
|
exit "${1:-1}"
|
|
}
|
|
|
|
# Arguments
|
|
while [[ -n $* ]]; do
|
|
case "$1" in
|
|
"--")
|
|
shift
|
|
ssh_options=("$@")
|
|
set --
|
|
;;
|
|
*)
|
|
args+=("$1")
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Checking the validity of the args
|
|
[[ -z ${args[2]} ]] && error 1
|
|
[[ -z ${args[3]} ]] && args[3]=localhost
|
|
|
|
# Command building
|
|
ssh_com=(
|
|
"$ssh"
|
|
"${ssh_options[@]}"
|
|
-f
|
|
-N
|
|
-L "${args[1]}:${args[3]}:${args[2]}"
|
|
"${args[0]}"
|
|
)
|
|
|
|
# Debug
|
|
#echo "${ssh_com[@]}"
|
|
#exit 0
|
|
|
|
# Execution
|
|
set -x
|
|
"${ssh_com[@]}"
|
|
|