On the Windows command line, how do I get a dynamic prompt that tells me my location in the filesystem?


Ancient Nissus

I'm trying to modify my CMD to display only the current directory name dynamically, eg:

Desktop $

When I switch folders, it has to be updated.

It doesn't need to be code in a pure batch file . It may depend on any external command, Cygwin Bash etc.

@echo off
set a=bash -c "pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'"
%a%
cmd

output

_test-et
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Tüm hakları saklıdır.
>>

but

>> prompt %a%

Give

bash -c "pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,'"
Harwich

Using Microsoft's PowerShell, the prompt is produced by a function that can do anything.

The prompt function that can do what you want is:

function prompt { (Split-Path -Leaf $pwd) + '$ ' }

For more information, see:

Related


How do I get the Windows command prompt to display the time?

Daniel Williams I want my command prompt (not powershell, just command prompt) to show the time like this: 14:02> Is there a way to do this? Basically, I have everything running from the prompt and am happy to see when I execute various commands. GroovyDotCom

How do I get the Windows command prompt to display the time?

Daniel Williams I want my command prompt (not powershell, just command prompt) to show the time like this: 14:02> Is there a way to do this? Basically, I have everything running from the prompt and am happy to see when I execute various commands. GroovyDotCom

How do I get the Windows version using the command line?

Yoder If I am in CMDI can usewinver I can see my OS version is 20H2now. But this is GUI result and I want to use command line to make it. if i use ver Microsoft Windows [Version 10.0.19042.868] If I'm in powershell, I can use Get-ComputerInfo WindowsVersion

How do I open a "custom" command prompt in Windows?

Hubro I have a flash drive with subversion, python, php and notepad++, and several projects I'm working on. I did this to be able to get back to work on any PC with an internet connection. Currently, I have a .bat file that sets the necessary paths as well as

How do I change the color palette of the Windows Command Prompt?

TWiStErRob First, I don't want this: How can I change the default colors of the command prompt? When I say palette, I mean the real scheme/palette, not just foreground+background. I would like to change the definitions of "dark red", "light green" etc so that

How do I open a "custom" command prompt in Windows?

Hubro I have a flash drive with subversion, python, php and notepad++, and several projects I'm working on. I did this to be able to get back to work on any PC with an internet connection. Currently, I have a .bat file that sets the necessary paths as well as

How do I change the color palette of the Windows Command Prompt?

TWiStErRob First, I don't want this: How can I change the default colors of the command prompt? When I say palette, I mean the real scheme/palette, not just foreground+background. I would like to change the definitions of "dark red", "light green" etc so that

ldd tells me my application is not a "dynamic executable"

Karl I have a 32-bit application (called uclsyn) from an astronomy professor. I managed to get it working on CentOS a year ago, but now when I set up a new CentOS VM it won't work and I can't figure out why. It always comes back with "kill". Here is the swap o

ldd tells me my application is not a "dynamic executable"

Karl I have a 32-bit application (called uclsyn) from an astronomy professor. I managed to get it working on CentOS a year ago, but now when I set up a new CentOS VM it won't work and I can't figure out why. It always comes back with "kill". Here is the swap o

How do I set the file location in the GST startup command line?

pablodepas87 I want to play avi video using gst-launch command line. I tried the videotest command line: gst-launch-1.0 videotestsrc!ximagesink This command line works fine, but if I want to play the video, how can I set the file path? My videos are in the opt

How do I set the file location in the GST startup command line?

pablodepas87 I want to play avi video using gst-launch command line. I tried the videotest command line: gst-launch-1.0 videotestsrc!ximagesink This command line works fine, but if I want to play the video, how can I set the file path? My videos are in the opt

How do I set the file location in the GST startup command line?

pablodepas87 I want to play avi video using gst-launch command line. I tried the videotest command line: gst-launch-1.0 videotestsrc!ximagesink This command line works fine, but if I want to play the video, how can I set the file path? My videos are in the opt

How do I get C:/ on the command line

username I am on Windows 10. I'm trying to load Adobe Dreamweaver extension via command line on Windows. I want to navigate to C:\Program Files\Adobe\Adobe Extension Manager CSx\ I am following the instructions here . If I select command prompt (admin), I getC

How do I get C:/ on the command line

username I am on Windows 10. I'm trying to load Adobe Dreamweaver extension via command line on Windows. I want to navigate to C:\Program Files\Adobe\Adobe Extension Manager CSx\ I am following the instructions here . If I select command prompt (admin), I getC