使用批处理脚本作为 ConEmu 任务

使用批处理脚本作为 ConEmu 任务

我经常需要使用 SSH 连接到各种服务器。我使用康德, 像那样 :

cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe root@server1" -new_console:C:"C:\Apps\cmder-git\icons\cmder.ico" -new_console:P:^<Ubuntu^> -new_console:t:server1

但我很懒,因此我想编写一个批处理脚本,该脚本只需一个参数即可连接到任何 SSH 端点(例如conssh root@server1:),并将被调用来从新控制台对话(创建与服务器一样多的 ConEmu 任务不是一种选择)。

命令行工具(在 %PATH% 内):

@echo off

:: Aliases
if "%1"=="s1" (
    set arg="root@server1"
) else if "%1"=="c1" (
    set arg="-t root@server1 ssh [email protected]"
) else (
    set arg=%1
)

:: cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail (works, but opens a useless tab : "ConEmuC: Root process was alive less than 10 sec, ExitCode=121.")

:: cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -cur_console:C:C:\Apps\cmder-git\icons\cmder.ico -cur_console:P:^<Ubuntu^> -cur_console:t:"%1"
:: => Fail (ConEmuC: Root process was alive less than 10 sec, ExitCode=1.)

:: "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail (ConEmuC: Root process was alive less than 10 sec, ExitCode=1.)

:: cmd /k "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail (works, but opens a useless tab : "ConEmuC: Root process was alive less than 10 sec, ExitCode=121.")

:: cmd /k "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -cur_console:C:C:\Apps\cmder-git\icons\cmder.ico -cur_console:P:^<Ubuntu^> -cur_console:t:"%1"
:: => Fail (opens a cmd.exe shell, not ssh)

:: cmd /c -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: cmd /c "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%"
:: => Fail (opens a useless tab, with wrong icon)

:: start /b "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:C:\Apps\cmder-git\icons\cmder.ico -new_console:P:^<Ubuntu^> -new_console:t:"%1"
:: => Fail

:: start /b "%ConEmuDir%\..\git-for-windows\usr\bin\ssh.exe %arg%" -cur_console:C:C:\Apps\cmder-git\icons\cmder.ico -cur_console:P:^<Ubuntu^> -cur_console:t:"%1"
:: => Fail

我怎样才能使其工作(只打开一个选项卡,使用正确的图标、调色板和标题)?

谢谢

答案1

我回答了我自己的问题,找到了一种解决方法ConEmu -Single(该脚本直接从 Windows Shell 运行,而不是新的控制台对话框):

@echo off

set cmderlocation=C:\Apps\cmder-git
set icon=cmder_blue.ico

:: Aliases
if "%1"=="s1" (
    set arg=root@server1
) else if "%1"=="c1" (
    set arg=-t root@server1 ssh [email protected]
) else (
    set arg=%*
    set icon=cmder_red.ico
)

"%cmderlocation%\vendor\conemu-maximus5\ConEmu.exe" -Single -run cmd /c "%cmderlocation%\vendor\git-for-windows\usr\bin\ssh.exe %arg%" -new_console:C:"%cmderlocation%\icons\%icon%" -new_console:P:^<Ubuntu^> -new_console:t:"%1"

相关内容