# This script must be sourced from the user's profile # set_prompt.s: set the bash prompt # By Vitek Gite and Lee Rothstein, 2008-05-22, 06:46 PM. # Vitek supplied the article and the comments, here. Lee # supplied the exact escape sequences to generate a prompt # such as: # [lr@GW2] [/local/Scripts] # 2010-01-08 Fri 02:32:17 PM # $ xp # in color. # The notes (comments), below, are largely quoted from an article # by Vitek Gite at the NixCraft forum: # http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix # Above article was still available as of 2010-01-08. # My editor, TextPad, http://TextPad.com, allows urls and my # browser to be accessed directly from text files. How about # yours? #PVersion="0.02.02.000" #PUpDate="2010-02-15, 17:38:29" #Textual Elements #================ # * \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 # # Colors # ====== # # To add colors to the shell prompt use the following export # command syntax: # '\e[x;ym $PS1 \e[m' # # Where, # * \e[ Start color scheme # * x;y Color pair to use (x;y) # * $PS1 is your shell prompt # * \e[m Stop color scheme # # To set a red color prompt, type the command: # # $ export PS1="\e[0;31m[\u@\h \W]\$ \e[m " # # Color Code # Black 0;30 # Red 0;31 # Green 0;32 # Brown 0;33 # Blue 0;34 # Purple 0;35 # Cyan 0;36 # # Replace lead digit 0 with 1, to get light color version. # # set on profile: # export PS1="\e[0;31m[\u@\h \W]\$ \e[m" # # * Put \[ and \] around any color codes so that bash does not # take them into account when calculating line wraps. Also you # can make use of the 'tput' command to have this work in any # terminal as long as the 'TERM' is set correctly. For instance # '$(tput setaf 1)' and '$(tput sgr0)' # LDR: Never able to get 'tput' to work, YMMV. set -a # Export all variables # All Work: # Today’s date and hostname: # $ PS1="\d \h $ " # PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$(date '+%Y-%m-%d %a %r') \n$ " # PS1="\[\e]0;\w\a\]\n\[\e[32m\][\u@\h] \[\e[33m\][\w]\[\e[0m\]\n\$(date '+%Y-%m-%d %a %r') \n$ " # PS1="\[\e]0;\w\a\]\n\[\e[32m\][\u@\h] \[\e[36m\][\w]\[\e[0m\]\n\$(date '+%Y-%m-%d %a %r') \n$ " # PS1="\[\e]0;\w\a\]\n\[\e[32m\][\u@\h] \[\e[36m\][\w]\[\e[0m\]\n\e[1;31m \$(date '+%Y-%m-%d %a %r')\n\e[m$ " # Note: if you don't escape the '$' in the subexpression '\$(date...', # it only computes the date/time at the time the prompt is # set, NOT on each prompt generated PS1="\[\e]0;\w\a\]\n\[\e[1;32m\][\u@\h] \[\e[1;36m\][\w]\[\e[0m\]\n\e[1;31m \$(date '+%Y-%m-%d, %H:%M:%S')\n\e[m$ " # For debugging with bashdb: PS4='(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]} - [${SHLVL},${BASH_SUBSHELL}, $?]'