mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-01-10 04:27:48 +08:00
feat(riot): sshl supports specifying local port and unix sock
This commit is contained in:
parent
e1f0ec0ebc
commit
426e97c10e
33
scripts/riot
33
scripts/riot
@ -195,16 +195,35 @@ run_ssh()
|
|||||||
# sshl
|
# sshl
|
||||||
run_sshl()
|
run_sshl()
|
||||||
{
|
{
|
||||||
local arg="$1"
|
is_port() {
|
||||||
if [[ "$arg" != *":"* ]]; then
|
if [[ "$1" =~ ^[1-9][0-9]*$ && $1 -gt 1 && $1 -lt 65535 ]]; then return 0; else return 1; fi
|
||||||
# treat as a port number
|
}
|
||||||
arg=localhost:$arg
|
res="${1//[^:]}"
|
||||||
|
if [[ ${#res} -eq 2 ]]; then
|
||||||
|
arg="$1"
|
||||||
|
elif [[ ${#res} -eq 0 ]]; then
|
||||||
|
arg="$(get_free_port):localhost:$1"
|
||||||
|
else
|
||||||
|
left=${1%%:*}
|
||||||
|
right=${1##*:}
|
||||||
|
if is_port "$left"; then
|
||||||
|
arg="$1"
|
||||||
|
elif is_port "$right"; then
|
||||||
|
arg="$(get_free_port):$1"
|
||||||
|
else
|
||||||
|
arg="$1"
|
||||||
|
localsock=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
local port=$(get_free_port)
|
if [[ "$localsock" == "1" ]]; then
|
||||||
SSH_OPTIONS+=("-NC" "-L" "$port:$arg")
|
access="unix://${arg%%:*}"
|
||||||
|
else
|
||||||
|
access="localhost:${arg%%:*}"
|
||||||
|
fi
|
||||||
|
SSH_OPTIONS+=("-NC" "-L" "$arg")
|
||||||
prepare_ssh_cmd ssh
|
prepare_ssh_cmd ssh
|
||||||
print_cmd
|
print_cmd
|
||||||
fmt_note " > please access localhost:$port"
|
fmt_note " > please access $access"
|
||||||
eval_or_echo
|
eval_or_echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user