bash PS1 - Serbipunk/notes GitHub Wiki
example
export PS1="\[\033[0;32m\]MLS \[\033[0;33m\]\w \[\033[0m\]"
green word : \[\033[0;32m\]
brown word : \[\033[0;33m\]
export PS1="\[\033[0;32m\]\u \[\033[0;33m\]\w \[\033[0m\]"
if you run ahead of conda, then conda setting is also works.
gpt answer:
The PS1
environment variable in a shell, like Bash, represents the primary prompt string, which is displayed at the start of each new command line in the terminal. This prompt is typically visible when the terminal is waiting for input from the user.
PS1
Common Elements in - Username: Displayed with
\u
. - Hostname: Displayed with
\h
. Shows the name of the machine. - Working Directory: Displayed with
\w
. Shows the full path of the current directory. - Basename of Working Directory: Displayed with
\W
. Shows only the current directory name, not the full path. - Date and Time: Various formats, e.g.,
\d
for the date. - Command Number: Displayed with
\!
. Shows the history number of the current command. - Exit Status of Last Command: Can be shown using a custom script or function.
- Root or Normal User: Displayed with
\$
. Shows#
for root and$
for normal users.
PS1
Common Modifications of - Changing Appearance: Users often customize
PS1
to change the color and format of the prompt for better readability or personal preference. For example, adding color codes like\[\033[0;32m\]
and\[\033[0m\]
around elements to make the username green. - Adding Information: Including additional information like the current Git branch, command execution time, or system information.
- Simplifying: Some users prefer a minimalistic prompt, showing only essential information to keep the display clean.
- Dynamic Content: Using functions to dynamically update parts of the prompt based on the current context, such as changing colors or information displayed based on the current directory or the success of the last command.
Example
A simple PS1
modification might look like this:
export PS1="\[\033[0;32m\]\u@\h \[\033[0;34m\]\W\[\033[0m\]\$ "
This sets the prompt to display the username in green, the hostname, and the basename of the working directory in blue, followed by a $
for a normal user or #
for the root, with each part separated by spaces.
Each user's preference for their PS1
configuration can greatly vary based on their workflow, the information they need, and their aesthetic choices.