gpt4 book ai didi

linux - 如何在windows中获取unix风格的提示符(批量)

转载 作者:太空宇宙 更新时间:2023-11-04 05:07:05 31 4
gpt4 key购买 nike

我正在尝试制作显示 unix/linux 提示符的 dos shell。代码是:

@echo off
:hi
set tmpdrv=%cd:~0,2%

if %homedrive% == %tmpdrv% (
set drvmatch=1
) else (
set drvmatch=0
)
set "MYSTRING=abcdef!%%^^()^!"
set MYSTRING=%homepath%
:strlen
(echo "%MYSTRING%" & echo.) | findstr /O . | more +1 | (set /P RESULT= & call exit /B %%RESULT%%)
set /A STRLENGTH=%ERRORLEVEL%-5
set tmppath1=%cd:~2%
CALL set tmppath2=%%tmppath1:~0,%STRLENGTH%%%
if %homepath% == %tmppath2% (
set homematch=1
) else (
set homematch=0
)

set homepathmatch=0
if %homepath% == %tmppath2% (
if %homedrive% == %tmpdrv% (
set homepathmatch=1
)
)

if %homepathmatch%==1 (
REM set /a STRLENGTH=%STRLENGTH%+2
CALL set newpath=%%tmppath1:~%STRLENGTH%%%
set newpath1=~%newpath%
)
set newpath2=%newpath1:\=/%
:check_Permissions

net session >nul 2>&1
if %errorLevel% == 0 (
set "username2=root"
) else (
set username2=%username%
)
set /p %command%="%username2%@%computername%:%newpath2%$ "
%command%
goto :hi

我希望它像 unix/linux 中一样显示目录名称,但它显示一个 ~。我的代码有什么问题?你能帮我改进一下吗?

最佳答案

可能不太清楚提示特定情况的子字符串修改,但设置提示的方法是。

@ECHO OFF & Setlocal EnableDelayedExpansion & TITLE %~n0
cls & MODE 1000 & CD %userprofile%\desktop


For /F "tokens=* Delims=\" %%A In ("%userprofile%") Do (
Set "C_Prompt=%%A"
Set "C_Prompt=!C_Prompt:\=!"
Set "C_Prompt=!C_Prompt:Users=!"
For %%A in (a,b,c,d,e,f,g,h,i) Do (Set "C_Prompt=!C_Prompt:%%A:=!")
)
Set DirPath=:!CD:\=/!
For %%A in (a,b,c,d,e,f,g,h,i) Do (Set "DirPath=!DirPath:%%A:=!")
Set "C_Prompt=!C_Prompt!@!computername!!DirPath! $$ "

prompt !C_Prompt!

Start /B cmd.exe

上面的内容不会刷新工作目录的命令提示符,但会导致命令按预期运行,而不会出现扩展问题。

This linked Macro will refresh the Prompt when the working Directory changes, however the act of expanding commands within a user defined variable can result in unexpected results.

关于linux - 如何在windows中获取unix风格的提示符(批量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60245450/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com