'Change Windows command prompt to show only current folder

Instead of showing

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

show

\etc

or if possible limit it to a certain number

\Document\Folder\etc


Solution 1:[1]

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.

Solution 2:[2]

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

Solution 3:[3]

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.

Solution 4:[4]

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

Solution 5:[5]

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

Love and peace, Joe

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chandre Gowda
Solution 2
Solution 3 Suraj Donthi
Solution 4 Bobby Wayne
Solution 5 Love and peace - Joe Codeswell