User:Grufo/Color System's Bash Prompt

From ArchWiki

This guide shows how to customize the default Bash Prompt of the whole system. For user-wide changes and for a step-by-step guide about colors and some other customizations, see also the article Color Bash Prompt.

Warning: You should back up any system-wide bash files you modify in /etc as simple syntax mistakes may break your shell.

There are a variety of possibilities for Bash's prompt (PS1), and customizing it can help you be more productive at the command line. You can add additional information to your prompt, or you can simply add color to it to make the prompt stand out. See this Forum thread for more informations and examples.

A well-established Bash color prompt

What follows is a well-proven way to color the Bash prompt. It is the most widespread Bash color scheme in the GNU/Linux world. Here is a preview of how it will appear:

I am two with nature.
                -- Woody Allen
andy@alba ~ $ ls
Desktop Documents Music public.desktop
andy@alba ~ $ I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found
andy@alba ~ :( $ echo 'Hello world!'
Hello world!
andy@alba su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel
alba ~ $ _

Installation

It's a generalized scheme for all users, so you should start renaming your ~/.bashrc file and then copy the /etc/bash.bashrc file to /etc/bash.bashrc.back and create a /etc/DIR_COLORS file (~/.bashrc and /etc/bash.bashrc can also cohabitate). Here is our possible version of this scheme for Arch (originally this scheme was created for Gentoo, but here are some important additions).

/etc/bash.bashrc

# /etc/bash.bashrc
#
# https://wiki.archlinux.org/index.php/Color_Bash_Prompt
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !

# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.

# If not running interactively, don't do anything!
[[ $- != *i* ]] && return

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

# Enable history appending instead of overwriting.
shopt -s histappend

case ${TERM} in
	xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
		PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
		;;
	screen)
		PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
		;;
esac

# fortune is a simple program that displays a pseudorandom message
# from a database of quotations at logon and/or logout.
# If you wish to use it, please install "fortune-mod" from the
# official repositories, then uncomment the following line:

#[[ "$PS1" ]] && /usr/bin/fortune

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions. Use internal bash
# globbing instead of external grep binary.

# sanitize TERM:
safe_term=${TERM//[^[:alnum:]]/?}
match_lhs=""

[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs} ]] \
	&& type -P dircolors >/dev/null \
	&& match_lhs=$(dircolors --print-database)

if [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] ; then

	# we have colors :-)

	# Enable colors for ls, etc. Prefer ~/.dir_colors
	if type -P dircolors >/dev/null ; then
		if [[ -f ~/.dir_colors ]] ; then
			eval $(dircolors -b ~/.dir_colors)
		elif [[ -f /etc/DIR_COLORS ]] ; then
			eval $(dircolors -b /etc/DIR_COLORS)
		fi
	fi

	PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\\$\[\033[00m\] "

	# Use this other PS1 string if you want \W for root and \w for all other users:
	# PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h\[\033[01;34m\] \W'; else echo '\[\033[01;32m\]\u@\h\[\033[01;34m\] \w'; fi) \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\\$\[\033[00m\] "

	alias ls="ls --color=auto"
	alias dir="dir --color=auto"
	alias grep="grep --color=auto"
	alias dmesg='dmesg --color'

	# Uncomment the "Color" line in /etc/pacman.conf instead of uncommenting the following line...!

	# alias pacman="pacman --color=auto"

else

	# show root@ when we do not have colors

	PS1="\u@\h \w \$([[ \$? != 0 ]] && echo \":( \")\$ "

	# Use this other PS1 string if you want \W for root and \w for all other users:
	# PS1="\u@\h $(if [[ ${EUID} == 0 ]]; then echo '\W'; else echo '\w'; fi) \$([[ \$? != 0 ]] && echo \":( \")\$ "

fi

PS2="> "
PS3="> "
PS4="+ "

# Try to keep environment pollution down, EPA loves us :-)
unset safe_term match_lhs

# Try to enable the auto-completion (type: "pacman -S bash-completion" to install it).
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion

# Try to enable the "Command not found" hook ("pacman -S pkgfile" to install it).
# See also: https://wiki.archlinux.org/index.php/Bash#The_.22command_not_found.22_hook
[ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash

Environment variables

There are also other programs which, to be colorized, require the setting of some environment variables. This is the case of man, for example:

export LESS_TERMCAP_mb=$'\E[01;31m' \
LESS_TERMCAP_md=$'\E[01;38;5;74m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_so=$'\E[38;5;246m' \
LESS_TERMCAP_ue=$'\E[0m' \
LESS_TERMCAP_us=$'\E[04;38;5;146m'

For more info, see: Environment Variables.

/etc/DIR_COLORS

# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.

# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR all

# Extra command line options for ls go here.
# Basically these ones are:
#  -F = show '/' for dirs, '*' for executables, etc.
#  -T 0 = don't trust tab spacing when formatting ls output.
OPTIONS -F -T 0

# Below, there should be one TERM entry for each termtype that is colorizable
TERM linux
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM xterm
TERM xterm-color
TERM xterm-256color
TERM vt100
TERM rxvt
TERM rxvt-256color
TERM rxvt-cygwin
TERM rxvt-cygwin-native
TERM rxvt-unicode
TERM rxvt-unicode-256color
TERM rxvt-unicode256
TERM screen

# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes: 
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00	# global default, although everything should be something.
FILE 00 	# normal file
DIR 01;34 	# directory
LINK 01;36 	# symbolic link
FIFO 40;33	# pipe
SOCK 01;35	# socket
BLK 40;33;01	# block device driver
CHR 40;33;01 	# character device driver

# This is for files with execute permission:
EXEC 01;32 

# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
.cmd 01;32 # executables (bright green)
.exe 01;32
.com 01;32
.btm 01;32
.bat 01;32
.tar 01;31 # archives or compressed (bright red)
.tgz 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.zip 01;31
.z   01;31
.Z   01;31
.gz  01;31
.jpg 01;35 # image formats
.gif 01;35
.bmp 01;35
.xbm 01;35
.xpm 01;35
.tif 01;35

/etc/pacman.conf

As of version 4.1, Pacman has a color option. In order to activate it, please, uncomment the #Color line in /etc/pacman.conf.

/etc/skel/

This tip shows you how to use /etc/skel/ directory to ensure that all new users on your system get the same initial settings.

The /etc/skel/ directory is the directory used by useradd to create the default settings in a new user's home directory.

To change the location of /etc/skel/, edit /etc/default/useradd.

# useradd defaults file 
GROUP=100 
HOME=/home 
INACTIVE=-1 
EXPIRE= 
SHELL=/bin/bash 
SKEL=/etc/skel

Typically files included in /etc/skel/ are .rc files for shell initialization, but you could also include a public_html directory, a custom .dir_colors file, or anything else.

andy@alba /etc/skel $ ls -A
.bash_logout .bash_profile .bashrc .xinitrc .xsession
andy@alba /etc/skel $ _

For more information on customizing the /etc/skel/ directory, type: $ man useradd. See also: http://www.gentoo.org/news/en/gwn/20031222-newsletter.xml.

Now, the /etc/skel/.bashrc file is the .bashrc file copyied into the home directory of each new user. It will look something like this:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

As you can see, a PS1 variable (i.e.: the prompt) is exported. So, if you had previously created a color prompt through the /etc/bash.bashrc file, each user newly created, to see it, should delete the line

PS1='[\u@\h \W]\$ '

from his own ~/.bashrc. Accordingly, if you want to grant to newly created users to have the same colorfull PS1, you should delete that line from /etc/skel/.bashrc.

Example of cohabitation of /etc/bash.bashrc and ~/.bashrc

~/.bashrc and /etc/bash.bashrc can also cohabitate. Usually the default GNU's ~/.bashrc file looks like this:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

As you can see, a PS1 variable (i.e.: the prompt) is exported. So, if you had previously created a color prompt through the /etc/bash.bashrc file, to see it you should delete that line: otherwise it will be overwritten.

Note: If you just remove the PS1 line above and don't replace it with some other bash aliases or functions or whatever you want, such a empty ~/.bashrc file will return a false value and a red sad smile will appear at the opening of every new session because of what we decided in our /etc/bash.bashrc file.

Tips and tricks

Random quotations at logon

For a brown Fortune prompt, add:

~/.bashrc
[[ "$PS1" ]] && echo -e "\e[00;33m$(/usr/bin/fortune)\e[00m"

Colorized Arch latest news at logon

To read 10 latest news items from the Arch official website, user grufo has written a small and coloured RSS escaping script (scrollable):

   :: Arch Linux: Recent news updates ::
 [ https://www.archlinux.org/news/ ]

The latest and greatest news from the Arch Linux distribution.

 en-us Sun, 04 Nov 2012 16:09:46 +0000


   :: End of initscripts support ::
 [ https://www.archlinux.org/news/end-of-initscripts-support/ ]


Tom Gundersen wrote:
As systemd is now the default init system, Arch Linux is receiving minimal testing on initscripts systems. Due to a lack of resources and interest, we are unlikely to work on fixing initscripts-specific bugs, and may close them as WONTFIX.
We therefore strongly encourage all users to migrate to systemd as soon as possible. See the systemd migration guide [ https://wiki.archlinux.org/index.php/Systemd ].
To ease the transition, initscripts support will remain in the official repositories for the time being, unless otherwise stated. As of January 2013, we will start removing initscripts support (e.g., rc scripts) from individual packages without further notice.

 Tom Gundersen Sun, 04 Nov 2012 16:09:46 +0000 tag:www.archlinux.org,2012-11-04:/news/end-of-initscripts-support/


   :: November release of install media available ::
 [ https://www.archlinux.org/news/november-release-of-install-media-available/ ]


Pierre Schmitz wrote:
The latest snapshot of our install and rescue media can be found on our Download [ https://www.archlinux.org/download/ ] page. The 2012.11.01 ISO image mainly contains minor bug fixes, cleanups and new packages compared to the previous one:
 * First media with Linux 3.6
 * copytoram=n can be used to not copy the image to RAM on network boot. This is probably unreliable but an option for systems with very low memory.
 * cowfile_size boot parameter mainly for persistent COW on VFAT. See the README [ https://projects.archlinux.org/archiso.git/plain/docs/README.bootparams?id=v4 ] file for details.

 Pierre Schmitz Fri, 02 Nov 2012 17:54:15 +0000 tag:www.archlinux.org,2012-11-02:/news/november-release-of-install-media-available/


   :: Bug Squashing Day: Saturday 17th November ::
 [ https://www.archlinux.org/news/bug-squashing-day-saturday-17th-november/ ]


Allan McRae wrote:
The number of bugs in the Arch Linux bug tracker is creeping up so it is time for some extermination.
This is a great way for the community to get involved and help the Arch Linux team. The process is simple. First look at a bug for your favorite piece of software in the bug tracker and check if it still occurs. If it does, check the upstream project for a fix and test it to confirm it works. If there is no fix available, make sure the bug has been filed in the upstream tracker.
Join us on the #archlinux-bugs IRC channel. We are spread across timezones, so people should be around all day.

 Allan McRae Thu, 01 Nov 2012 12:28:51 +0000 tag:www.archlinux.org,2012-11-01:/news/bug-squashing-day-saturday-17th-november/


   :: ConsoleKit replaced by logind ::
 [ https://www.archlinux.org/news/consolekit-replaced-by-logind/ ]


Allan McRae wrote:
With GNOME 3.6, polkit and networkmanager moving to [extra], ConsoleKit has now been removed from the repositories. Any package that previously depended on it now relies on systemd-logind instead. That means that the system must be booted with systemd to be fully functional.
In addition to GNOME, both KDE and XFCE are also affected by this change.

 Allan McRae Tue, 30 Oct 2012 22:17:39 +0000 tag:www.archlinux.org,2012-10-30:/news/consolekit-replaced-by-logind/


   :: systemd is now the default on new installations ::
 [ https://www.archlinux.org/news/systemd-is-now-the-default-on-new-installations/ ]


Thomas Bächler wrote:
The base group now contains the systemd-sysvcompat package. This means that all new installations will boot with systemd by default.
As some packages still lack native systemd units, users can install the initscripts package and use the DAEMONS array in /etc/rc.conf to start services using the legacy rc.d scripts.
This change does not affect existing installations. For the time being, the initscripts and sysvinit packages remain available from our repositories. However, individual packages may now start relying on the system being booted with systemd.
Please refer to the wiki [ https://wiki.archlinux.org/index.php/Systemd ] for how to transition an existing installation to systemd.

 Thomas Bächler Sat, 13 Oct 2012 09:29:38 +0000 tag:www.archlinux.org,2012-10-13:/news/systemd-is-now-the-default-on-new-installations/


   :: Install medium 2012.10.06 introduces systemd ::
 [ https://www.archlinux.org/news/install-medium-20121006-introduces-systemd/ ]


Pierre Schmitz wrote:
The October release of the Arch Linux install medium is available for Download [ https://www.archlinux.org/download/ ] and can be used for new installs or as a rescue system. It contains a set of updated packages and the following notable changes:
 * systemd is used to boot up the live system.
 * initscripts are no longer available on the live system but are still installed by default on the target system. This is likely to change in the near future.
 * EFI boot and setup has been simplified.
 * gummiboot is used to display a menu on EFI systems.
 * The following new packages are available on the live system: ethtool, fsarchiver, gummiboot-efi, mc, partclone, partimage, refind-efi, rfkill, sudo, testdisk, wget, xl2tpd

 Pierre Schmitz Sun, 07 Oct 2012 16:58:03 +0000 tag:www.archlinux.org,2012-10-07:/news/install-medium-20121006-introduces-systemd/


   :: New install medium 2012.09.07 ::
 [ https://www.archlinux.org/news/new-install-medium-20120907/ ]


Pierre Schmitz wrote:
As is customary by now there is a new install medium available at the beginning of this month. The live system can be downloaded from Download [ https://www.archlinux.org/download/ ] and be used for new installs or as a rescue system.
In addition to a couple of updated packages and bug fixes the following changes stand out:
 * First medium with Linux 3.5 (3.5.3)
 * The script boot parameter works again (FS#31022 [ https://bugs.archlinux.org/task/31022 ])
 * When booting via PXE and NFS or NBD the ISO will be copied to RAM to ensure a more stable usage.
 * The live medium contains usb_modeswitch and wvdial which e.g. allows to establish a network connection using an UMTS USB dongle
 * Furthermore the newest versions of initscripts, systemd and netcfg are included.

 Pierre Schmitz Sat, 08 Sep 2012 09:48:52 +0000 tag:www.archlinux.org,2012-09-08:/news/new-install-medium-20120907/


   :: Fontconfig 2.10.1 update - manual intervention required ::
 [ https://www.archlinux.org/news/fontconfig-2101-update-manual-intervention-required/ ]


Andreas Radke wrote:
The fontconfig 2.10.1 update overwrites symlinks created by the former package version. These symlinks need to be removed before the update:

rm /etc/fonts/conf.d/20-unhint-small-vera.conf
rm /etc/fonts/conf.d/20-fix-globaladvance.conf
rm /etc/fonts/conf.d/29-replace-bitmap-fonts.conf
rm /etc/fonts/conf.d/30-metric-aliases.conf
rm /etc/fonts/conf.d/30-urw-aliases.conf
rm /etc/fonts/conf.d/40-nonlatin.conf
rm /etc/fonts/conf.d/45-latin.conf
rm /etc/fonts/conf.d/49-sansserif.conf
rm /etc/fonts/conf.d/50-user.conf
rm /etc/fonts/conf.d/51-local.conf
rm /etc/fonts/conf.d/60-latin.conf
rm /etc/fonts/conf.d/65-fonts-persian.conf
rm /etc/fonts/conf.d/65-nonlatin.conf
rm /etc/fonts/conf.d/69-unifont.conf
rm /etc/fonts/conf.d/80-delicious.conf
rm /etc/fonts/conf.d/90-synthetic.conf
pacman -Syu fontconfig

Main systemwide configuration should be done by symlinks (especially for autohinting, sub-pixel and lcdfilter):

cd /etc/fonts/conf.d
ln -s ../conf.avail/XX-foo.conf

Also check Font Configuration [ https://wiki.archlinux.org/index.php/Font_Configuration ] and Fonts [ https://wiki.archlinux.org/index.php/Fonts ].

 Andreas Radke Thu, 06 Sep 2012 13:54:23 +0000 tag:www.archlinux.org,2012-09-06:/news/fontconfig-2101-update-manual-intervention-required/


   :: netcfg-2.8.9 drops deprecated rc.conf compatibility ::
 [ https://www.archlinux.org/news/netcfg-289-drops-initscripts-compatibility/ ]


Florian Pritz wrote:
Users of netcfg should configure all interfaces in /etc/conf.d/netcfg rather than /etc/rc.conf.

 Florian Pritz Sat, 11 Aug 2012 20:00:02 +0000 tag:www.archlinux.org,2012-08-11:/news/netcfg-289-drops-initscripts-compatibility/


   :: Install media 2012.08.04 available ::
 [ https://www.archlinux.org/news/install-media-20120804-available/ ]


Pierre Schmitz wrote:
The August snapshot of our live and install media comes with updated packages and the following changes on top of the previous ISO image [ /news/install-media-20120715-released/ ]:
 * GRUB 2.0 instead of the legacy 0.9 version is available.
 * The Installation Guide [ https://wiki.archlinux.org/index.php/Installation_Guide ] can be found at /root/install.txt.
 * ZSH with Grml's configuration [ http://grml.org/zsh/ ] is used as interactive shell to provide a user friendly and more convenient environment. This includes completion support for pacstrap, arch-chroot, pacman and most other tools.
 * The network daemon is started by default which will automatically setup your network if DHCP is available.
Note that all these changes only affect the live system and not the base system you install using pacstrap. The ISO image can be downloaded from our download page [ /download/ ]. The next snapshot is scheduled for September.

 Pierre Schmitz Sat, 04 Aug 2012 17:24:30 +0000 tag:www.archlinux.org,2012-08-04:/news/install-media-20120804-available/


andy@alba _
~/.bashrc
# Arch latest news
if [ "$PS1" ] && [[ $(ping -c1 www.google.com 2>&-) ]]; then
	# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
	echo -e "$(echo $(curl --silent https://www.archlinux.org/feeds/news/ | sed -e ':a;N;$!ba;s/\n/ /g') | \
		sed -e 's/&amp;/\&/g
		s/&lt;\|&#60;/</g
		s/&gt;\|&#62;/>/g
		s/<\/a>/£/g
		s/href\=\"/§/g
		s/<title>/\\n\\n\\n   :: \\e[01;31m/g; s/<\/title>/\\e[00m ::\\n/g
		s/<link>/ [ \\e[01;36m/g; s/<\/link>/\\e[00m ]/g
		s/<description>/\\n\\n\\e[00;37m/g; s/<\/description>/\\e[00m\\n\\n/g
		s/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g
		s/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/\\e[01;30m/g; s/<\/b>\|<\/strong>/\\e[00;37m/g
		s/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/\\e[41;37m/g; s/<\/i>\|<\/em>/\\e[00;37m/g
		s/<u\( [^>]*\)\?>/\\e[4;37m/g; s/<\/u>/\\e[00;37m/g
		s/<code\( [^>]*\)\?>/\\e[00m/g; s/<\/code>/\\e[00;37m/g
		s/<a[^§|t]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g
		s/<li\( [^>]*\)\?>/\n \\e[01;34m*\\e[00;37m /g
		s/<!\[CDATA\[\|\]\]>//g
		s/\|>\s*<//g
		s/ *<[^>]\+> */ /g
		s/[<>£§]//g')\n\n";
fi

To only get the absolute latest item, use this:

# Arch latest news
if [ "$PS1" ] && [[ $(ping -c1 www.google.com 2>&-) ]]; then
	# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
	echo -e "$(echo $(curl --silent https://www.archlinux.org/feeds/news/ | awk ' NR == 1 {while ($0 !~ /<\/item>/) {print;getline} sub(/<\/item>.*/,"</item>") ;print}' | sed -e ':a;N;$!ba;s/\n/ /g') | \
		sed -e 's/&amp;/\&/g
		s/&lt;\|&#60;/</g
		s/&gt;\|&#62;/>/g
		s/<\/a>/£/g
		s/href\=\"/§/g
		s/<title>/\\n\\n\\n   :: \\e[01;31m/g; s/<\/title>/\\e[00m ::\\n/g
		s/<link>/ [ \\e[01;36m/g; s/<\/link>/\\e[00m ]/g
		s/<description>/\\n\\n\\e[00;37m/g; s/<\/description>/\\e[00m\\n\\n/g
		s/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g
		s/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/\\e[01;30m/g; s/<\/b>\|<\/strong>/\\e[00;37m/g
		s/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/\\e[41;37m/g; s/<\/i>\|<\/em>/\\e[00;37m/g
		s/<u\( [^>]*\)\?>/\\e[4;37m/g; s/<\/u>/\\e[00;37m/g
		s/<code\( [^>]*\)\?>/\\e[00m/g; s/<\/code>/\\e[00;37m/g
		s/<a[^§|t]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g
		s/<li\( [^>]*\)\?>/\n \\e[01;34m*\\e[00;37m /g
		s/<!\[CDATA\[\|\]\]>//g
		s/\|>\s*<//g
		s/ *<[^>]\+> */ /g
		s/[<>£§]//g')\n\n";
fi

Variations on a theme

Here are some PS1 variables (i.e.: prompts) with different layout to be applyied to our /etc/bash.bashrc file. When you choose a layout you must replace the following lines from our /etc/bash.bashrc file:

	PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\$\[\033[00m\] "

	# Use this other PS1 string if you want \W for root and \w for all other users:
	# PS1="$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h\[\033[01;34m\] \W'; else echo '\[\033[01;32m\]\u@\h\[\033[01;34m\] \w'; fi) \$([[ \$? != 0 ]] && echo \"\[\033[01;31m\]:(\[\033[01;34m\] \")\$\[\033[00m\] "

with the PS1 variable (and possibly other code lines) given by the choosen layout.

From Arch Forum #1

Here is an unicode variation of our /etc/bash.bashrc file freely based on what wrote the user JeSuisNerd and others in the Arch Forum. Here is a preview of how it will appear:

I am two with nature.
                -- Woody Allen
┌─[andy@alba]─[~]
└──╼ ls
Desktop Documents Music public.desktop
┌─[andy@alba]─[~]
└──╼ I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found
┌─[]─[andy@alba]─[~]
└──╼ echo 'Hello world!'
Hello world!
┌─[andy@alba]─[~]
└──╼ su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel
┌─[alba]─[~]
└──╼ _

Note: Some unicode symbols (like and ╼) are not well supported in some terminals (in linux console, for example), so this prompt will appear a bit different depending on where is displayed. If you want to know the unicode representation of a plain text, here you have a little plain text converter.

And finally here is the PS1 variable for this effect to be applyied to our /etc/bash.bashrc file (see above):

	# https://bbs.archlinux.org/viewtopic.php?pid=1068202#p1068202
	PS1="\[\033[0;37m\]\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[0;31m\]\h'; else echo '\[\033[0;33m\]\u\[\033[0;37m\]@\[\033[0;96m\]\h'; fi)\[\033[0;37m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;37m\]]\n\[\033[0;37m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]"

From an italian blog…

Here is an unicode variation of our /etc/bash.bashrc file freely based on an italian blog. Here is a preview of how it will appear:

I am two with nature.
                -- Woody Allen
┌─[12:03:20]─[andy@alba]
└──> ~ $ ls
Desktop Documents Music public.desktop
┌─[12:03:31]─[andy@alba]
└──> ~ $ I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found
┌─[]─[12:04:01]─[andy@alba]
└──> ~ $ echo 'Hello world!'
Hello world!
┌─[12:04:13]─[andy@alba]
└──> ~ $ su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel
┌─[12:04:21]─[root@alba]
└──> ~ $ _

Note: Some unicode symbols (like ✗) are not well supported in some terminals (in linux console, for example), so this prompt will appear a bit different depending on where is displayed. If you want to know the unicode representation of a plain text, here you have a little plain text converter.

And finally here is the PS1 variable for this effect to be applyied to our /etc/bash.bashrc file (see above):

	if [[ ${EUID} == 0 ]] ; then
		sq_color="\[\033[0;31m\]"
	else		
		sq_color="\[\033[0;34m\]"
	fi

	PS1="$sq_color\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[01;37m\]\342\234\227$sq_color]\342\224\200\")[\[\033[01;37m\]\t$sq_color]\342\224\200[\[\033[01;37m\]\u@\h$sq_color]\n\342\224\224\342\224\200\342\224\200> \[\033[01;37m\]\W$sq_color $ \[\033[01;37m\]>>\\[\\033[0m\\] "

	unset sq_color

From Arch Forum #2

Here is another variation of our /etc/bash.bashrc file freely based on what wrote the user shumer1213 and others in the Arch Forum. Here is a preview of how it will appear:

I am two with nature.
                -- Woody Allen

██ [ ~ ] [ 18:05:58 ]
██ ls
Desktop Documents Music public.desktop

██ [ ~ ] [ 18:06:02 ]
██ I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found

██ [ ~ ] [ 18:06:12 ]
██ echo 'Hello world!'
Hello world!

██ [ ~ ] [ 18:06:17 ]
██ su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel

██ [ andy ] [ 18:06:26 ]
██ _

Here is the PS1 variable for this effect to be applyied to our /etc/bash.bashrc file (see above):

	# https://bbs.archlinux.org/viewtopic.php?pid=1156660#p1156660
	PS1="\n\$(if [[ \$? == 0 ]]; then echo \"\[\033[0;34m\]\"; else echo \"\[\033[0;31m\]\"; fi)\342\226\210\342\226\210 [ \W ] [ \t ]\n\[\033[0m\]\342\226\210\342\226\210 "

With directory information

Here are other three variations of our /etc/bash.bashrc file freely based on the article 8 Useful and Interesting Bash Prompts. Here is a preview of how they will appear:

Version #1: with numerical error

I am two with nature.
                -- Woody Allen

┌(andy@alba)─(0)─(02:38 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> ls
Desktop Documents Music myScript.js

┌(andy@alba)─(0)─(02:38 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found

┌(andy@alba)─(127)─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> echo 'Hello world!'
Hello world!

┌(andy@alba)─(0)─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> false

┌(andy@alba)─(1)─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel

┌(alba)─(0)─(02:39 PM Sat Aug 29)
└─(/home/andy)─(4 files, 332Kb)─> _

Here is the PS1 variable for this effect to be applyied to our /etc/bash.bashrc file (see above):

	# http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04
	PS1="\n\[\033[1;37m\]\342\224\214($(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;34m\]\u@\h'; fi)\[\033[1;37m\])\342\224\200(\[\033[1;34m\]\$?\[\033[1;37m\])\342\224\200(\[\033[1;34m\]\@ \d\[\033[1;37m\])\[\033[1;37m\]\n\342\224\224\342\224\200(\[\033[1;32m\]\w\[\033[1;37m\])\342\224\200(\[\033[1;32m\]\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -sh | head -n1 | sed 's/total //')b\[\033[1;37m\])\342\224\200> \[\033[0m\]"

Version #2: with unicode error status symbols

I am two with nature.
                -- Woody Allen

┌(andy@alba)─()─(02:38 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> ls
Desktop Documents Music myScript.js

┌(andy@alba)─()─(02:38 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found

┌(andy@alba)─()─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> echo 'Hello world!'
Hello world!

┌(andy@alba)─()─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> false

┌(andy@alba)─()─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel

┌(alba)─()─(02:39 PM Sat Aug 29)
└─(/home/andy)─(4 files, 332Kb)─> _

Here is the PS1 variable for this effect to be applyied to our /etc/bash.bashrc file (see above):

	# http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04
	PS1="\n\[\033[1;37m\]\342\224\214($(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;34m\]\u@\h'; fi)\[\033[1;37m\])\342\224\200(\$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\]\342\234\223\"; else echo \"\[\033[01;31m\]\342\234\227\"; fi)\[\033[1;37m\])\342\224\200(\[\033[1;34m\]\@ \d\[\033[1;37m\])\[\033[1;37m\]\n\342\224\224\342\224\200(\[\033[1;32m\]\w\[\033[1;37m\])\342\224\200(\[\033[1;32m\]\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -sh | head -n1 | sed 's/total //')b\[\033[1;37m\])\342\224\200> \[\033[0m\]"

Version #3: with unicode error status symbol (non-zero only)

I am two with nature.
                -- Woody Allen

┌(andy@alba)─(02:38 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> ls
Desktop Documents Music myScript.js

┌(andy@alba)─(02:38 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> I\ will\ try\ to\ type\ a\ wrong\ command...
bash: I will try to type a wrong command...: command not found

┌(andy@alba)─()─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> echo 'Hello world!'
Hello world!

┌(andy@alba)─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> false

┌(andy@alba)─()─(02:39 PM Sat Aug 29)
└─(~)─(4 files, 332Kb)─> su
Password:
Two can Live as Cheaply as One for Half as Long.
                -- Howard Kandel

┌(alba)─(02:39 PM Sat Aug 29)
└─(/home/andy)─(4 files, 332Kb)─> _

Here is the PS1 variable for this effect to be applyied to our /etc/bash.bashrc file (see above):

	# http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04
	PS1="\n\[\033[1;37m\]\342\224\214($(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;34m\]\u@\h'; fi)\[\033[1;37m\])\$([[ \$? != 0 ]] && echo \"\342\224\200(\[\033[0;31m\]\342\234\227\[\033[1;37m\])\")\342\224\200(\[\033[1;34m\]\@ \d\[\033[1;37m\])\[\033[1;37m\]\n\342\224\224\342\224\200(\[\033[1;32m\]\w\[\033[1;37m\])\342\224\200(\[\033[1;32m\]\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -sh | head -n1 | sed 's/total //')b\[\033[1;37m\])\342\224\200> \[\033[0m\]"

Restoring the original /etc/bash.bashrc file

If you repent having modified the /etc/bash.bashrc file, you can always restore the original Arch /etc/bash.bashrc file from the bash package (the file can be found here) and remove the /etc/DIR_COLORS file.

See also

External links