1

Is it possible to have the command prompt automatically run a command before every command that is entered?

The problem is sometimes when I kill the web server I am running to develop with in the command prompt with 'CTRL' + 'c' the process will change the color of the command prompt. This will linger in the command prompt and leave the color purple, making things hard to read. Currently when this happens I run color 07 before I start the server again. Is there a way to automatically run color 07 in the background when I type the next command so I always start with white?

2 Answers2

2

You can adjust the prompt text by setting the PROMPT variable. This may allow you to use an ANSI escape code to reset the text color to default. Since some command prompt windows have ANSI color support turned on and some do not, it is difficult for me to tell if this will work as-is, but you can try it:

set PROMPT=$e[0m$P$G

If it does not work as-is, you could try one of a number of solutions to enable ANSI escape codes.

Dark Falcon
  • 43,592
  • 5
  • 83
  • 98
0

Since it sounds like you want the color command before you run the server, you can just make an alias to your command which runs both.

Try this?

Edit: The general part of your question seems to be answered here for linux shell. If cygwin is available you could use that solution and still run your commands in windows. Could not find a trap equivalent for windows.

Community
  • 1
  • 1
code11
  • 1,986
  • 5
  • 29
  • 37
  • I could use this to a backup if my original question is unsolvable. I would prefer not making an alias though, as if I want to pass different flags or even a different server call I would have to make new aliases. I need something more dynamic, just something that will automatically run `color 07` before every command entered. Thank you for this though, we will wait and see if someone has the magical answer :) ! – Alexander Lallier Aug 19 '16 at 14:00