From 9ca03f54012d35b1ffb610d8518af8d498184e6a Mon Sep 17 00:00:00 2001 From: luk Date: Mon, 24 Aug 2026 00:36:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ssh.sh=20=E6=9C=AA=E4=BC=A0=20$2=20?= =?UTF-8?q?=E6=97=B6=E9=BB=98=E8=AE=A4=E5=9C=A8=E8=BF=9C=E7=A8=8B=E9=99=84?= =?UTF-8?q?=E5=8A=A0=20tmux=20=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有 tmux 则执行 tmux a,无可附加会话时自动开新会话(tmux a || tmux new), 无 tmux 则回退到交互式 shell。 Co-Authored-By: AtomCode (deepseek-v4-flash) --- ssh.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ssh.sh b/ssh.sh index 8a0288c..848d033 100755 --- a/ssh.sh +++ b/ssh.sh @@ -81,16 +81,23 @@ if [ "$port" = "null" ]; then port=22 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}" if [ "$password" != "null" ]; then if command -v sshpass &> /dev/null; then - echo "::*** sshpass -p $password -Y -p $port $username@$host '$2'" - sshpass -p "$password" ssh -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" "$cmd" else - echo "::*** ssh -Y -p $port $username@$host '$2'" - ssh -Y -p "$port" "$username@$host" "$2" + echo "::*** ssh -Y -p $port $username@$host '$cmd'" + ssh -Y -p "$port" "$username@$host" "$cmd" fi else - echo "::*** ssh -Y -p $port $username@$host '$2'" - ssh -Y -p "$port" "$username@$host" "$2" + echo "::*** ssh -Y -p $port $username@$host '$cmd'" + ssh -Y -p "$port" "$username@$host" "$cmd" fi \ No newline at end of file