Bash Prompt PS1
tput
tput
sets terminal-dependent capabilities, colors and positions. To test the prompt, paste the code at the bottom of your .bashrc
file. The exec bash
command refreshes Bash.
FGBG1
The variable FGBG1="\[$(tput bold; tput setaf 3; tput setab 4)\]"
contains formatting for username:
tput bold
sets username text to bold.tput setaf 3
sets text color to yellow.tput setab 4
sets username background color to blue.
FGBG2
The variable FGBG2="\[$(tput bold; tput setaf 4; tput setab 3)\]"
contains formatting for current working directory:
tput bold
sets username text to bold.tput setaf 4
sets text color to blue.tput setab 3
sets username background color to yellow.
RESET
The variable RESET="\[$(tput sgr0\)]"
resets all attributes back to default settings. In other words, it closes or ends the formatting.
export
As you can see, both formatting variables, along with the reset variable, are included in the Bash export statement export PS1="${FGBG1} \u:${FGBG2} \w ${RESET} 🤓 \$ "
. Notice the prompt variable characters \u
and \w
for username and current working directory. Finally, there are the nerd face emoji, which can be replaced with a unicorn, or whatever, along with the \$
variable character, which inserts a $
at the CLI prompt.
There ya go. Now your Bash prompt is nerdier than it was before.
Prompt #2
export PS1="\e[36;44m\u💎\e[7m\w\e[0m\$ "
\e
escape[36;44m
cyan foreground/blue background\u
username💎
diamond emoji\e
escape[7m
invert foreground color/background color\w
current working directory\e
escape[0m
reset to default theme\$
prompt character which changes to#
inroot
privileges.
Prompt #3
The third version of the Bash prompt pipes instructions to Python 3. For example, $(echo -e "import os;print(os.getlogin())" | python3)
pipes the quoted instructions to Python 3 which imports the os
module and executes getlogin()
which returns user name of login.