Bash prompts
============
(o que eu utilizo)
\[\033[0;33m\][\!]`if [[ $? = 0 ]]; then echo \[\033[32m\]; else echo \[\033[31m\]; fi`[\u.\h: `if [[ 12 > 18 ]]; then echo \W; else echo \w; fi`]$\[\033[0m\]
(simples, sem cores)
PS1="\u@\h:\w/ > "
if [ "$PS1" ]; then
# Is this terminal able to use this prompt?
case $TERM in
xterm*|rxvt*|cygwin*)
# Am I root?
if [ $UID = 0 ]; then
PS1='\[\e]0;\w | \u@\h\a\][\[\e[1;31m\]\u@\h \[\e[33m\]\W\[\e[0m\]]# '
else
PS1='\[\e]0;\w | \u@\h\a\][\[\e[32m\]\u@\h \[\e[33m\]\W\[\e[0m\]]$ '
fi
;;
esac
fi
Caracteres Especiais
====================
Bash allows these prompt strings to be customized by inserting a
number of backslash-escaped special characters that are
decoded as follows:
\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
Cores
=====
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
Links
=====
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
http://www.nparikh.org/unix/prompt.php
Dicas
=====
Remove Color
Echo \e[00m to remove text color modifications
\[ begins a sequence of non-printing characters
\] ends a sequence of non-printing characters
##################################################
# Fancy PWD display function
##################################################
# The home directory (HOME) is replaced with a ~
# The last pwdmaxlen characters of the PWD are displayed
# Leading partial directory names are striped off
# /home/me/stuff -> ~/stuff if USER=me
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
##################################################
bash_prompt_command() {
# How many characters of the $PWD should be kept
local pwdmaxlen=25
# Indicate that there has been dir truncation
local trunc_symbol=".."
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
if [ ${pwdoffset} -gt "0" ]
then
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
fi
}
Idéias
======
Cor vermelha para sudo