How to Change Bash Prompt

From OESF

Revision as of 19:09, 11 October 2005 by Bam (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

1. Make a file called profile 2. Open said file 3. Look at examples and see what you like(ie create your own)

  a. PS1="(\d \u@\h : \W)\n (\T) $ "<---this is what goes in the file

4. Look at the codes and modify as desired. 5. Save file and move to /etc directory (works on 3100, not sure about the rest)

Codes: \a an ASCII bell character (07) \d the date in "Weekday Month Date" format (e.g., "Tue May 26") \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 \u the username of the current user \v the version of bash (e.g., 2.00) \V the release of bash, version + patchlevel (e.g., 2.00.0) \w the current working directory \W the basename of the current working direc­ tory \! 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 con­ trol sequence into the prompt \] end a sequence of non-printing characters


More Examples:

Example 1:

  PROMPT_HOSTNAME='SET_HERE'
  PROMPT_COLOR='1;37m'
  PROMPT_COLOR2='1;32m'
  PS1='\e[${PROMPT_COLOR}[\e[${PROMPT_COLOR2}\u@${PROMPT_HOSTNAME}\e[${PROMPT_COLOR}] $ '

Example 2:

  PS1='\n\[\033[1;34m\]\342\226\210\342\226\210 \u @ \w\n\[\033[0;36m\]\342\226\210\342\226\210 \t $ \[\033[0;39m\]'

Example 3:(extreme but cool, a function)

  function jobcount {
  jobs | wc -l | tr -d " "

}

cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")

loadavg=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g")

  1. PROMPT

PS1='\[\033[1;44m\]\[\033[1;34m\] \[\033[1;40m\] [\u@\h:\w]\n\[\033[1;44m\]\[\033[1;34m\] \[\033[1;40m\] [j:`jobcount`, t:$cur_tty, l:$loadavg]\n\[\033[1;46m\]\[\033[1;36m\] \[\033[1;40m\] [`date +%D` \t] $> \[\033[0;39m\]'

You get the general idea...have fun :)

Personal tools