Change Windows command prompt to show only current folder
Asked Answered
C

5

7

Instead of showing

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

show

\etc

or if possible limit it to a certain number

\Document\Folder\etc
Candracandy answered 9/6, 2017 at 21:31 Comment(2)
There's not a simple way in cmd.exe. PowerShell is a different story: Just put the code you want into the prompt function.Emikoemil
If your goal is to maximizing typing space and get a consistent prompt placement, I think the best one can do in cmd is to use a prompt string like [$P]$_$G, which moves the ">" prompt to a separate line.String
S
8

If you check in help prompt /? there are two options that can either show the current drive or full path.

I would suggest to use new line option along with the Drive so that you will get more space to view/type the command using below combination.

prompt $P$_$G

With this you will be able to see the Path in the line above the prompt.

Sheik answered 26/7, 2018 at 7:36 Comment(0)
R
1

The following is a simple batch script which can set the prompt to include only the current folder. Note that it does not work on directory names with certain characters such as parenthesis and spaces. I named it cdd.bat.

@echo off
cd %1

for %%i in (%CD%) do set NEWDIR=%%~ni
PROMPT %NEWDIR%$G
Restrict answered 21/11, 2019 at 19:26 Comment(1)
use %* instead of %1Gowk
V
0

In short, can't see a simple way of doing it. In order to change the prompt options you can use the prompt command. The configuration you're looking for isn't listed. The available options can be viewed by prompt /? in the command window.

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

Victoriavictorian answered 9/6, 2017 at 21:43 Comment(3)
This would be a better answer if you actually said which option to use.Klink
Please read the question again carefully. Your answer does not answer the original question.Osteoclast
I figured it was pretty self evident from the link.Victoriavictorian
G
-1

Like others pointed out, you can use the command - prompt to set the text that is shown in cmd.

While you cannot dynamically set the path to just the parent folder, you can manually set it using:

prompt {text}

So in your case, you can set it as:

prompt etc\$G

This will result in:

etc\>

$G adds an arrow sign. You can refer the documentation for detailed explanation.

Gerena answered 12/11, 2019 at 4:47 Comment(0)
S
-1

Here is a .ps1 file i use to do this for myself.

<#
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://learn.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://learn.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."

Love and peace, Joe

Sydelle answered 30/6, 2020 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.