查看clink.bat
文件
让我们来看一下clink.bat文件:
:: Copyright (c) 2012 Martin Ridgers
:: License: http:
@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
这段代码有很好的注释,因此我们能够看到以下的时间顺序结构:
- 移动到
%userprofile%
文件夹
- 如果调用是以
clink.bat --profile PROFILE_DIR
的形式进行的,则将clink_profile_arg
设置为PROFILE_DIR
的值
- 如果没有参数,则跳转到
launch
代码,然后结束(通过跳转到文件末尾)
- 根据系统的架构(技术上调用此函数的进程架构: %PROCESSOR_ARCHITECTURE%的可能值),选择正确的
.exe
launch
"定义"(技术上是标签)
你已经正确地确认了可以更改的launch
标记代码,让我们进一步查看它:
start "Clink" cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
因此,这里使用一些参数来运行 start
命令,包括字符串 "Clink" 以及一个带有自己命令行参数的 cmd.exe
。其中 %~dpnx0
表示:驱动器、路径、文件名、扩展名和第0个参数(参见 syntax-args),而 %clink_profile_arg%
是之前定义的变量。
查看 start
:
启动一个新的命令提示符窗口,用于运行指定的程序或命令。
粗体 强调是我自己加的,但我们立即可以看到为什么您观察到了所描述的行为。
现在我们有几个选项要考虑。
选项1 - 基于 clink.bat
的新 clink_terminal.bat
虽然我们可以编辑 clink.bat
,但更好的选择是制作一个单独的文件,专门用于终端。
我们只需将 :launch
更改为:
cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
然后使用 clink_terminal.bat
替换你的命令行,并直接使用 clink
的命令行参数。
选项 2 - 直接使用 clink
命令行参数
希望您已经了解到可以有效地替换调用 .bat
,并直接调用带有其参数的 clink
。
这里假设您正在使用 x64 机器:
commandline: "cmd.exe /s /k "PATH_TO_CLINK\\clink_x64.exe inject --profile PROFILE_DIR""
设置GUID!!!
终端中的所有配置文件都有一个GUID,您可以轻松生成一个自己的GUID。
打开PowerShell窗口并运行new-guid
PS C:\ANYWHERE> New-Guid
Guid
----
c97d08e9-03fc-491f-bbd7-9a12b9d6e191