User Tools

Site Tools


fancy_prompt_cookbook

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fancy_prompt_cookbook [2010/06/17 14:39] (current)
tkbletsc created
Line 1: Line 1:
 +====== Fancy prompt cookbook ======
 +
 +It is nice to make your bash prompt look good.  Here is a base script that defines all the ANSI colors as variables and sets up a clear PS1 prompt variable.  I usually save this as ".bashprompt" and source it from ".bashrc".
 +
 +<code bash>R="\[\e[m\]"
 +RESET="\[\e[m\]"
 +BOLD="\[\e[1m\]"
 +FAINT="\[\e[2m\]"
 +UNDERLINE="\[\e[4m\]"
 +REVERSE="\[\e[7m\]"
 +STRIKEOUT="\[\e[9m\]"
 +LO_BLACK="\[\e[30m\]"
 +LO_RED="\[\e[31m\]"
 +LO_GREEN="\[\e[32m\]"
 +LO_YELLOW="\[\e[33m\]"
 +LO_BLUE="\[\e[34m\]"
 +LO_MAGENTA="\[\e[35m\]"
 +LO_CYAN="\[\e[36m\]"
 +LO_WHITE="\[\e[37m\]"
 +HI_BLACK="\[\e[30;90m\]"
 +HI_RED="\[\e[31;91m\]"
 +HI_GREEN="\[\e[32;92m\]"
 +HI_YELLOW="\[\e[33;93m\]"
 +HI_BLUE="\[\e[34;94m\]"
 +HI_MAGENTA="\[\e[35;95m\]"
 +HI_CYAN="\[\e[36;96m\]"
 +HI_WHITE="\[\e[37;97m\]"
 +BG_BLACK="\[\e[40m\]"
 +BG_RED="\[\e[41m\]"
 +BG_GREEN="\[\e[42m\]"
 +BG_YELLOW="\[\e[43m\]"
 +BG_BLUE="\[\e[44m\]"
 +BG_MAGENTA="\[\e[45m\]"
 +BG_CYAN="\[\e[46m\]"
 +BG_WHITE="\[\e[47m\]"
 +
 +
 +# ======================= BASH PROMPT ESCAPE CODES  ==========================
 +# == Time & Date ==
 +# \t Time in 24-hour HH:MM:SS format    \T Time in 12-hour HH:MM:SS format   
 +# \A Time in 24-hour HH:MM format       \@ Time in 12-hour HH:MM AP format
 +# \d Date, e.g. "Tue May 26"             
 +
 +# == Characters ==
 +# \a ASCII bell                         \e ASCII escape character
 +# \n Newline                            \r Carriage return
 +# \[ Start of non-printing characters   \] End of non-printing characters
 +# \\ A backslash
 +
 +# == Shell Info ==
 +# \v Short version (e.g. "4.0"        \V Long version (e.g. "4.0.33")
 +# \! History number of this command     \# Command number of this command
 +# \j Number of jobs                     \l Basename of the shell's terminal device
 +# \s Shell name (e.g. "bash"                 
 +
 +# == Current Environment ==
 +# \h Short hostname                     \H Full hostname
 +# \w Current working directory          \W Basename of the current directory
 +# \u Current username
 +# \$ Shell prompt (either '$' or '#')
 +
 +
 +if [ `whoami` = "root" ]
 +then
 + export PS1="$BG_RED$HI_YELLOW\u${HI_WHITE}@${HI_YELLOW}\h$HI_BLACK:$HI_GREEN\w $HI_WHITE\$$R "
 +else
 + #export PS1="$BG_BLUE$LO_CYAN\u${HI_CYAN}@${LO_CYAN}\h$HI_BLACK:$HI_GREEN\w $HI_WHITE\$$R "
 + #export PS1="$BG_BLUE$LO_MAGENTA\u${HI_MAGENTA}@${LO_MAGENTA}\h$HI_BLACK:$HI_GREEN\w $HI_WHITE\$$R "
 + export PS1="$BG_BLUE$LO_GREEN\u${HI_GREEN}@${LO_GREEN}\h$HI_BLACK:$HI_GREEN\w $HI_WHITE\$$R "
 +fi
 +
 +unset R RESET BOLD FAINT UNDERLINE REVERSE STRIKEOUT LO_BLACK LO_RED LO_GREEN LO_YELLOW LO_BLUE LO_MAGENTA LO_CYAN LO_WHITE 
 +unset HI_BLACK HI_RED HI_GREEN HI_YELLOW HI_BLUE HI_MAGENTA HI_CYAN HI_WHITE BG_BLACK BG_RED BG_GREEN BG_YELLOW BG_BLUE BG_MAGENTA BG_CYAN BG_WHITE
 +
 +</code>
 +
 +Also, if your environment isn't updating the tab titles in your graphical terminal, you can append the following line to fix that:
 +<code bash>
 +export PS1="\[\e]0;\u@\h:\w\a\]$PS1"
 +</code>
  
fancy_prompt_cookbook.txt ยท Last modified: 2010/06/17 14:39 by tkbletsc