feat: ssh.sh 未传 $2 时默认在远程附加 tmux 会话
有 tmux 则执行 tmux a,无可附加会话时自动开新会话(tmux a || tmux new), 无 tmux 则回退到交互式 shell。 Co-Authored-By: AtomCode (deepseek-v4-flash) <noreply@atomgit.com>
This commit is contained in:
19
ssh.sh
19
ssh.sh
@@ -81,16 +81,23 @@ if [ "$port" = "null" ]; then
|
|||||||
port=22
|
port=22
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 未提供 $2 时,默认在远程执行:若装有 tmux 则 tmux a(附加到已有会话),否则进入交互式 shell
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
cmd="$2"
|
||||||
|
else
|
||||||
|
cmd='if command -v tmux >/dev/null 2>&1; then tmux a || tmux new; else exec "${SHELL:-sh}"; fi'
|
||||||
|
fi
|
||||||
|
|
||||||
echo "::*** Connecting to ${label}"
|
echo "::*** Connecting to ${label}"
|
||||||
if [ "$password" != "null" ]; then
|
if [ "$password" != "null" ]; then
|
||||||
if command -v sshpass &> /dev/null; then
|
if command -v sshpass &> /dev/null; then
|
||||||
echo "::*** sshpass -p $password -Y -p $port $username@$host '$2'"
|
echo "::*** sshpass -p $password -Y -p $port $username@$host '$cmd'"
|
||||||
sshpass -p "$password" ssh -Y -p "$port" "$username@$host" "$2"
|
sshpass -p "$password" ssh -Y -p "$port" "$username@$host" "$cmd"
|
||||||
else
|
else
|
||||||
echo "::*** ssh -Y -p $port $username@$host '$2'"
|
echo "::*** ssh -Y -p $port $username@$host '$cmd'"
|
||||||
ssh -Y -p "$port" "$username@$host" "$2"
|
ssh -Y -p "$port" "$username@$host" "$cmd"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "::*** ssh -Y -p $port $username@$host '$2'"
|
echo "::*** ssh -Y -p $port $username@$host '$cmd'"
|
||||||
ssh -Y -p "$port" "$username@$host" "$2"
|
ssh -Y -p "$port" "$username@$host" "$cmd"
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user