Created
November 11, 2019 06:25
-
-
Save Milly/639852c44564b0150b7895a4b06a1611 to your computer and use it in GitHub Desktop.
Inject clink to cmd.exe, if it is interactive running.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@setlocal enableextensions disabledelayedexpansion | |
@echo off | |
if not x%CMDNOINIT% == x goto :done | |
call :check_interactive "%CMDCMDLINE:"=""%" | |
if ERRORLEVEL 2 goto :interactive_silent | |
if ERRORLEVEL 1 goto :interactive | |
goto :done | |
:check_interactive | |
set test="%~1" | |
set test=%test:|=#% | |
set test=%test:&=#% | |
set test=%test:>=#% | |
set test=%test:<=#% | |
for /F "tokens=*" %%i in (%test%) do set test=%%i | |
set test=%test:""="% | |
call :check_interactive_rel %test% | |
goto :eof | |
:check_interactive_rel | |
shift | |
if /i x%1 == x/c goto :eof | |
if /i x%1 == x/k exit /b 2 | |
if x%1 == x exit /b 1 | |
goto :check_interactive_rel | |
:interactive_silent | |
set clink_opt=--quiet --profile ~\clink | |
goto :interactive_core | |
:interactive | |
echo %~f0: is interactive | |
set clink_opt=--profile ~\clink | |
goto :interactive_core | |
:interactive_core | |
:: Inject clink | |
set clink_path="%clink_dir%\clink.bat" | |
if exist %clink_path% call %clink_path% inject %clink_opt% | |
:done | |
@endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage