Cygwin custom prompt

The next information is taken from here it is not mine. I am trying to fix my prompt in a new machine that doesn't show up anything, not even the folder where it is i found this:

Prompt is control via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variable. If set, the value is executed as a command prior to issuing each primary prompt.

  • PS1 - The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is s-v$ .
  • PS2 - The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
  • PS3 - The value of this parameter is used as the prompt for the select command
  • PS4 - The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +

How do I display current prompt setting?

Simply use echo command, enter:

echo $PS1


\\u@\h \\W]\\$

How do I modify or change the prompt?

Modifying the prompt is easy task. Just assign a new value to PS1 and hit enter key: My old prompt --> [vivek@105r2 ~]$

PS1="touch me : "

output: My new prompt

touch me :

So when executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:

  • a : an ASCII bell character (07)
  • d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
  • D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
  • e : an ASCII escape character (033)
  • h : the hostname up to the first '.'
  • H : the hostname
  • j : the number of jobs currently managed by the shell
  • l : the basename of the shell’s terminal device name
  • n : newline
  • r : carriage return
  • s : the name of the shell, the basename of $0 (the portion following the final slash)
  • t : the current time in 24-hour HH:MM:SS format
  • T : the current time in 12-hour HH:MM:SS format
  • @ : the current time in 12-hour am/pm format
  • A : the current time in 24-hour HH:MM format
  • u : the username of the current user
  • v : the version of bash (e.g., 2.00)
  • V : the release of bash, version + patch level (e.g., 2.00.0)
  • w : the current working directory, with $HOME abbreviated with a tilde
  • W : the basename of the current working directory, with $HOME abbreviated with a tilde
  • ! : the history number of this command
  • # : the command number of this command
  • $ : if the effective UID is 0, a #, otherwise a $
  • nnn : the character corresponding to the octal number nnn
  • \ : a backslash
  • [ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  • ] : end a sequence of non-printing characters

the SP1 value is stored in /etc/bash.bashrc at first i didn't have that file so I just copy the one in my other machine and it worked perfect. here is the file:

# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software.
# If not, see .

# base-files version 4.1-1

# /etc/bash.bashrc: executed by bash(1) for interactive shells.

# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/bash.bashrc

# Modifying /etc/bash.bashrc directly will prevent
# setup from updating it.

# System-wide bashrc file

# Check that we haven't already been sourced.
([[ -z ${CYG_SYS_BASHRC} ]] && CYG_SYS_BASHRC="1") || return

# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return

# Set a default prompt of: user@host and current_directory
PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '

# Uncomment to use the terminal colours set in DIR_COLORS
# eval "$(dircolors -b /etc/DIR_COLORS)"


Comments powered by Disqus