Change Cygwin Prompt

17

6

The default cygwin prompt of "user@computer path \n $" is too long for me. I would like to keep the path.

I want it to become:

path $

Is there a config file I can modify to do this?

Cristian

Posted 2009-07-17T00:59:54.267

Reputation: 333

Possible duplicate of Is it possible to change my terminal window prompt text?

– phuclv – 2018-09-08T09:08:59.887

How to change the format of the bash prompt? – phuclv – 2018-09-08T09:09:22.353

Answers

26

The PS1 environment variable controls the prompt:

PS1='\w $ '

For more information on this and other prompt configuration topics, type man bash (assuming bash is your shell) and see the "PROMPTING" section.

To make this change permanent, edit your ~/.bashrc file to add the above line.

Greg Hewgill

Posted 2009-07-17T00:59:54.267

Reputation: 5 099

1~/.bashrc does not get executed for a login shell. update ~/.bash_profile instead. I use the following prompt string, which has some other useful information, not just the path: PS1='[\e[32m]\t [\e[33m]\w [\e[31m]! [\e[0m]$ ' – bobmcn – 2009-08-26T20:16:48.667

1Don't forget that normally .profile sources .bashrc, so that in effect, a login shell is initialized with the same stuff than a non-login shell plus what's in .profile. If that's the case, putting your new prompt in .bashrc kills two birds with one stone. – None – 2014-01-15T14:06:29.027

1

Not sure why having less context is better than having more... The fact that there is a new line in the prompt means the length of the prompt should not be an issue, but try this:

PS1='\[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

or

export PS1='\[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

This gives you a coloured prompt:

/full/path/to/current/folder
$your command text here

That way, you always see your full folder context but still get a full line to input text. (I left out the customary space following the '$' because it's coloured for clarity).

Colours are:
    1. '/full/path/...' = yellow;
    2. '$' (on next line) = cyan;
    3. 'your command text...' = light grey.

For those who DO want the 'user@hostname ' context too:

PS1='\[\e[1;32m\]\u\[\e[1;35m\]@\[\e[1;32m\]\h \[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

or

export PS1='\[\e[1;32m\]\u\[\e[1;35m\]@\[\e[1;32m\]\h \[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

This gives you a coloured prompt:

user@hostname /full/path/to/current/folder
$your command text here

This is my preference.

Colours are:
    1. 'user' = (light) green;
    2. '@' = pink;
    3. 'hostname' = (light) green;
    4. '/full/path/...' = yellow;
    5. '$' (on next line) = cyan;
    6. 'your command text...' = light grey.

(No, there are no spelling mistakes in this post - Queen's English ;) )

skeetastax

Posted 2009-07-17T00:59:54.267

Reputation: 101

1

.bashrc didn't work for me. I added this to the end of /etc/profile and it worked:

export PS1="\[\e[33m\]\w\[\e[0m\] \$ "

I'm using Cygwin version 2.11.2 (latest version as of 2018-12-18).

Samuel

Posted 2009-07-17T00:59:54.267

Reputation: 113

1

A login shell is one whose first character of argument zero is a -, or one started with the --login option. When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.

So it depends...i dont't use the --login, so i must add it to ~/.bashrc

jr00n

Posted 2009-07-17T00:59:54.267

Reputation: 11

0

Put this in your ~/.bashrc. Gives a coloured prompt and keeps the status in a single line.

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\$ "

Sandeep

Posted 2009-07-17T00:59:54.267

Reputation: 101