5

Is there a .bashrc like file that Windows cmd shell reads on start-up?

I'd like to set a shorter prompt, the default prompt shows the full path to the current directory and it gets messy when I descend down several levels of sub-directories. Currently, I'm manually calling the PROMPT command whenever the displayed path gets too long. It'll be nice to set it automatically.

DigitalEye
  • 1,456
  • 3
  • 17
  • 26
  • Duplicate ? http://stackoverflow.com/questions/4895966/changing-default-startup-directory-for-command-prompt-in-windows-7 – Superdrac Apr 23 '14 at 16:53
  • @Superdrac: I don't think so. I'm looking for a solution where in I can set the PROMPT in a startup file (similar to an `export PS1=...` statement in .bashrc). – DigitalEye Apr 23 '14 at 18:38
  • Newer answers have been posted that affect cmd.exe directly, meaning you can launch cmd.exe and get desired results instead of launching it through a separate file. SETX especially is a quick and easy way and it should be accepted so that other people looking for an answer find it first and can solve their problem. – Xbox One Apr 02 '21 at 15:57

3 Answers3

6

As an alternative to SETX, you can create a batch file that will effectively act as .bashrc. Then create a registry key called AutoRun under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor and set the path to that file as a value.

David Airapetyan
  • 5,301
  • 4
  • 40
  • 62
5

You can control the command line prompt either with the command PROMPT or with the variable PROMPT. For an example, the following two commands have the same effect:

  1. PROMPT $G
    
  2. SET PROMPT=$G
    

Ultimately, however, it is the variable that determines the prompt's formatting, and when you are using the command, it merely sets the variable for you.

With that in mind, you could just assign a default value to the PROMPT variable using the SETX command:

SETX PROMPT "$G"

From now on, even after you reboot the system, every new1 CMD session's prompt will be formatted as $G by default, until you change the variable again or reset it (globally). You can globally reset a variable by assigning it an empty value like this:

SETX PROMPT ""

1The CMD session that issues the SETX is not affected.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
4

You can use a batch file to launch a cmd prompt:

@echo off
cmd /k prompt $g
foxidrive
  • 40,353
  • 10
  • 53
  • 68