diff --git a/scripts/riot b/scripts/riot index fe11a78..c33dcfa 100755 --- a/scripts/riot +++ b/scripts/riot @@ -195,16 +195,35 @@ run_ssh() # sshl run_sshl() { - local arg="$1" - if [[ "$arg" != *":"* ]]; then - # treat as a port number - arg=localhost:$arg + is_port() { + if [[ "$1" =~ ^[1-9][0-9]*$ && $1 -gt 1 && $1 -lt 65535 ]]; then return 0; else return 1; fi + } + 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 - local port=$(get_free_port) - SSH_OPTIONS+=("-NC" "-L" "$port:$arg") + if [[ "$localsock" == "1" ]]; then + access="unix://${arg%%:*}" + else + access="localhost:${arg%%:*}" + fi + SSH_OPTIONS+=("-NC" "-L" "$arg") prepare_ssh_cmd ssh print_cmd - fmt_note " > please access localhost:$port" + fmt_note " > please access $access" eval_or_echo }