繁体   English   中英

更改 Windows 命令提示符以仅显示当前文件夹

[英]Change Windows command prompt to show only current folder

而不是显示

C:\Users\test_user\Documents\Folder\etc

显示

\etc

或者如果可能的话将其限制在某个数量

\Document\Folder\etc

如果您签入帮助prompt /? 有两个选项可以显示当前驱动器或完整路径。

我建议将新行选项与驱动器一起使用,以便您获得更多空间来使用以下组合查看/键入命令。

prompt $P$_$G

有了这个,您将能够在提示上方的行中看到路径。

就像其他人指出的那样,您可以使用命令prompt设置 cmd 中显示的文本

虽然您不能仅动态设置父文件夹的路径,但您可以使用以下方法手动设置它:

prompt {text}

因此,在您的情况下,您可以将其设置为:

prompt etc\$G

这将导致:

etc\>

$G添加一个箭头符号。 您可以参考文档以获取详细说明。

总之,看不到一个简单的方法。 为了更改提示选项,您可以使用 prompt 命令。 您要查找的配置未列出。 可用选项可以通过提示符 /? 在命令窗口中。

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prompt.mspx?mfr=true

以下是一个简单的批处理脚本,可以将提示设置为仅包含当前文件夹。 请注意,它不适用于带有某些字符(例如括号和空格)的目录名称。 我将它命名为cdd.bat。

@echo off
cd %1

for %%i in (%CD%) do set NEWDIR=%%~ni
PROMPT %NEWDIR%$G

这是我用来为自己执行此操作的 .ps1 文件。

<#
FileName: promptPsShort.ps1

To set the prompt to the last folder name in the path:
> function prompt {$l=Get-Location; $p="$l".split("\")[-1]; "PS $p> "}  
  # works at cmd prompt, BUT NOT DIREECTLY from a .ps1 file.

RESEARCH

1. google: powershell 7 copy text into clipboard
  [How to copy text from PowerShell](https://superuser.com/q/302032/236556)
  [Set-Clipboard](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/?view=powershell-7)
2. google: powershell escape double quote
  [Escaping in PowerShell](http://www.rlmueller.net/PowerShellEscape.htm)
3. google: powershell raw string
  [About Quoting Rules](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7)

4. Usage example: powershell
PS C:\flutter_beta\flutter\examples\catalog\android\app\src\main> pwd

Path
----
C:\flutter_beta\flutter\examples\catalog\android\app\src\main

PS C:\flutter_beta\flutter\examples\catalog\android\app\src\main> promptPsShort.ps1
Paste the current Clipboard contents into the Powershell Command Line and press Enter.
PS C:\flutter_beta\flutter\examples\catalog\android\app\src\main> function prompt {$l=Get-Location; $p="$l".split("\")[-1]; "PS $p> "}
PS main>
PS main>
PS main>

#>


$shortPromptCmdStr = @'
function prompt {$l=Get-Location; $p="$l".split("\")[-1]; "PS $p> "}
'@

Set-Clipboard -Value $shortPromptCmdStr

write-host "Paste the current Clipboard contents into the Powershell Command Line and press Enter."

爱与和平,乔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM