Skip to main content

Using .bashrc to Customize Bash Terminal

 

General Syntax

Basic Syntax:
\e[ : Start color scheme.
\033: equivalent to \e as an escape code
x;y : Color pair to use (x;y)
$PS1 : Your shell prompt variable.
\e[m : Stop color scheme.
\H: Display FQDN hostname.
\@: Display current time in 12-hour am/pm format
\u: Display the current username .
\h: Display the hostname
\W: Print the base of current working directory.
\$: Display # (indicates root user) if the effective UID is 0, otherwise display a $.

Following the codes below and syntax above,
Toss this escape code in to colorize everything green after:
\e[\[0;32m\]

## Black       0;30     Dark Gray     1;30
## Blue        0;34     Light Blue    1;34
## Green       0;32     Light Green   1;32
## Cyan        0;36     Light Cyan    1;36
## Red         0;31     Light Red     1;31
## Purple      0;35     Light Purple  1;35
## Brown       0;33     Yellow        1;33
## Light Gray  0;37     White         1;37

More bash references:
\a The ASCII bell character (you can also type \007)
\d Date in “Sat Sep 04″ format
\e ASCII escape character (you can also type \033)
\h First part of hostname (such as “mybox”)
\H Full hostname (such as “mybox.mydomain.com”)
\j The number of processes you’ve suspended in this shell by hitting ^Z
\l The name of the shell’s terminal device (such as “ttyp4″)
\n Newline
\r Carriage return
\s The name of the shell executable (such as “bash”)
\t Time in 24-hour format (such as “23:59:59″)
\T Time in 12-hour format (such as “11:59:59″)
\@ Time in 12-hour format with am/pm
\u Your username
\v Version of bash (such as 2.04)
\V Bash version, including patchlevel
\w Current working directory (such as “/home/koithara”)
\W The “basename” of the current working directory (such as “koithara”)
\! Current command’s position in the history buffer
\# Command number (this will count up at each prompt, as long as you type something)
\$ If you are not root, inserts a “$”; if you are root, you get a “#”
\xxx Inserts an ASCII character based on three-digit number xxx (replace unused digits with zeros, such as “\007″)
\\ A backslash

\[ This sequence should appear before a sequence of characters that don’t move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly.
\] This sequence should appear after a sequence of non-printing characters.

Misuse of escape sequences \[ and \] - Cannot use symbols:
\e[\[0;31m\]\hސ\uސ[\e[\[0;32m\]\w\e[\[0;31m\]]\@:ഽ_\$?\n߆\s\e[\[0;32m\]╼$

Correct escape sequences, misuse of symbols: (Omit 'f' next to \u)
\[\033[1;31m\]\hސ\uސ f\[\033[0;32m\]\w\[\033[1;31m\]]\@:ഽ_\$?\n߆\s\[\033[0;32m\]╼$

 

Translating Symbols for use in .bashrc


Search up a symbol to get UTF8 - https://www.compart.com/en/unicode/search?q=#characters
ഽ = 0xE0 0xB4 0xBD

Take the UTFx8 encoding and run it through wolfram -https://www.wolframalpha.com/
(Separate by commas, clean up spacing first: 0xE0, 0xB4, 0xBD)
0xE0, 0xB4, 0xBD = \340\264\275

Depending on encoding of the system (LANG=US.utf8), take the base conversion into bashrc or export command:
export PS1="\340\264\275" returns ഽ


export PS1="\336\220"
Correct escape sequences and symbols:
\[\033[1;31m\]\h\336\220\u\336\220\[\033[0;32m\]\w\[\033[1;31m\]]\@:\340\264\275_\$?\n\337\206\s\[\033[0;32m\]\342\225\274$


Correct:
export PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\\$\[\e[0m\]"

\? Display previous command exit status* Maybe?


Environment Variables


PS1: environment variable which contains the value of the default prompt. It changes the shell command prompt appearance and environment.
PS2: environment variable which contains the value the prompt used for a command continuation interpretation. You see it when you write a long command in many lines.
PS3: environment variable which contains the value of the prompt for the select operator inside the shell script.
PS4: environment variable which contains the value of the prompt used to show script lines during the execution of a bash script in debug mode.

 

Exportable Examples

Any of the below exports can be pasted directly into the terminal to be tested. Once the terminal is closed, these settings will be lost, so no worries about getting back to default.

߄
No color Parrotsec:
export PS1='┌──˨\u@\h─[\w]\n└──╼\$'

Full Parrot:
export PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\\$\[\e[0m\]"

Custom Parrot
export PS1='┌──˨\u@\h─[\w]\n└──╼\$ےސސސސ'

Last cmd exit Status; {pi@kappi:~_0}$ ; 0=status
export PS1="{\[\e[32m\]\u\[\e[m\]@\[\e[36m\]\h\[\e[m\]:\W_\$?}$ "

Colorized; [pi@kappi:~]$
export PS1="\[\e[32m\][\[\e[m\]\[\e[31m\]\u\[\e[m\]\[\e[33m\]@\[\e[m\]\[\e[32m\]\h\[\e[m\]:\[\e[36m\]\w\[\e[m\]\[\e[32m\]]\[\e[m\]\[\e[32;47m\]\\$\[\e[m\] "

Red; ┌─[$
export PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$"

Important escape code note:
export PS1="\e[\[0;31m\]ސސސ[\w]\n\s╼$"
is the same as
export PS1="\033[\[0;31m\]ސސސ[\w]\n\s╼$"

Current:
export PS1="\e[\[0;31m\]\hސ\uސ[\e[\[0;32m\]\w\e[\[0;31m\]]\@:ഽ_\$?\n߆\s\e[\[0;32m\]╼$"


Tests:

export PS1="\e[\[0;31m\]ސސސ[\e[\[0;32m\]\w\e[\[0;31m\]]\n\s╼$"

export PS1="\e[\[0;31m\]ސސސ[\w]\n\s╼$"

export PS1="\e[\[0;31m\]ސ\hސ[\e[\[0;32m\]\w\e[\[0;31m\]]\@߄\$?\n߆\s\e[\[0;32m\]╼$"

export PS1="\e[\[0;31m\]ސ\hސ[\e[\[0;32m\]\w\e[\[0;31m\]]\@ - \$?\n\s\e[\[0;32m\]╼$"

export PS1="\e[\[0;31m\]ސ\hސ[\e[\[0;32m\]\w\e[\[0;31m\]]\@:ഽ_\$?\n߆\s\e[\[0;32m\]╼$"

export PS1="\e[\[0;31m\]ސ\hސ[\e[\[0;32m\]\w\e[\[0;31m\]]\@:\$?\n߆\e[\[1;31m\]෴๏\e[\[0;31m\]\s\e[\[0;32m\]╼$"