在 Windows Terminal Preview 中运行 Clink

6 windows windows-terminal

是否有可能在Windows Terminal Preview 中运行Clink


我试图在设置中添加这个条目:

        {
            "hidden": false,
            "name": "Clink",
            "fontFace" : "Consolas",
            "fontSize" : 10,
            "commandline": "\"C:\\Program Files (x86)\\clink\\0.4.9\\clink.bat\" startmenu --profile ~\\clink"
        }
Run Code Online (Sandbox Code Playgroud)

但它会在新窗口中打开 Clink。

我认为clink.bat必须以某种方式进行修改,因为它启动了 Clink:

start "Clink" cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
Run Code Online (Sandbox Code Playgroud)

Ade*_*had 5

查看clink.bat文件

让我们看看clink.bat文件:

:: Copyright (c) 2012 Martin Ridgers
:: License: http://opensource.org/licenses/MIT

@echo off

:: Mimic cmd.exe's behaviour when starting from the start menu.
if /i "%1"=="startmenu" (
    cd /d "%userprofile%"
    shift /1
)

:: Check for the --profile option.
if /i "%1"=="--profile" (
    set clink_profile_arg=--profile "%~2"
    shift /1
    shift /1
)

:: If the .bat is run without any arguments, then start a cmd.exe instance.
if "%1"=="" (
    call :launch
    goto :end
)

:: Pass through to appropriate loader.
if /i "%processor_architecture%"=="x86" (
        "%~dp0\clink_x86.exe" %*
) else if /i "%processor_architecture%"=="amd64" (
    if defined processor_architew6432 (
        "%~dp0\clink_x86.exe" %*
    ) else (
        "%~dp0\clink_x64.exe" %*
    )
)

:end
set clink_profile_arg=
goto :eof

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:launch
start "Clink" cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
exit /b 0

Run Code Online (Sandbox Code Playgroud)

这是很好的评论,因此我们可以看到以下按时间顺序排列的结构:

  1. 移动到%userprofile%文件夹
  2. 如果调用在表单中clink_profile_argPROFILE_DIR则将设置为 的值clink.bat --profile PROFILE_DIR
  3. 如果没有参数跳转到launch代码然后结束(通过跳转到文件末尾)
  4. .exe根据系统架构选择右侧(技术上调用此函数的进程架构:%PROCESSOR_ARCHITECTURE% 的可能值
  5. launch“定义”(技术标签

您已经正确识别出launch标记代码是可以更改的,让我们进一步看一下:

start "Clink" cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
Run Code Online (Sandbox Code Playgroud)

所以这会运行start带有一些参数的命令,包括字符串“Clink”和cmd.exe带有自己的命令行参数的 a 。%~dpnx0为:d RIVE,p ATH,Ñ火焰,E X张力,0个参数(参见,语法ARGS),和%clink_profile_arg%前面定义的变量。

看着start

启动单独的命令提示符窗口以运行指定的程序或命令。

大胆的重点是我自己的,但我们现在马上可以看到为什么你观察到您所描述的行为。

我们现在有几个选择要考虑。

选项 1 - 新的clink_terminal.bat基于clink.bat

虽然我们可以编辑clink.bat更好的选择是制作一个单独的文件,我们只用于终端。

我们可以简单地:launch改为:

cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
Run Code Online (Sandbox Code Playgroud)

然后用你的commandline:withclink_terminal.bat代替。

选项 2 - 直接使用clink其命令行参数

希望通过您已经看到,您可以有效地替换调用.bat并且clink直接使用其参数直接调用。

这里假设您使用的是 x64 机器:

commandline: "cmd.exe /s /k "PATH_TO_CLINK\\clink_x64.exe inject --profile PROFILE_DIR""
Run Code Online (Sandbox Code Playgroud)

设置一个GUID!!!

终端中的所有配置文件都有一个 GUID,您可以轻松地自己生成一个。

打开 PowerShell 窗口并运行 new-guid

PS C:\ANYWHERE> New-Guid

Guid
----
c97d08e9-03fc-491f-bbd7-9a12b9d6e191
Run Code Online (Sandbox Code Playgroud)

  • 我打赌这个 GUID 会成为 Windows Terminal clink 集成的事实上的标准! (3认同)