BASH Prompt Customization

By xngo on March 4, 2019

Examples

# ~/.bashrc: executed by bash(1) for non-login shells.
 
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
 
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
 
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
 
# Define what to display on the command line.
export PS1="\t@\H:\w # "
 
# Keep track of all your command lines in ~/.bash_eternal_history file forever.
export HISTTIMEFORMAT="%s "
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER \
               "$(history 1)" >> ~/.bash_eternal_history'
# #########
# Some shortcuts for different directory listings
alias ls='ls -hFA --color=tty'                 # classify files in colour
alias dir='ls -A --color=auto --format=vertical'
alias vdir='ls -A --color=auto --format=long'
alias ll='ls -lA'                              # long list
alias la='ls -A'                              # all but . and ..
alias l='ls -CFA'                              #
 
alias grep='grep --color'                     # show differences in colour
 
# Default to human readable figures
alias df='df -h'
alias du='du -h'
alias du1='du --max-depth=1'
 
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
 
# Define what to display on the command line: e.g. --=[2015-05-26 14:00:32 @root]=--
# http://askubuntu.com/a/24422
red=$(tput setaf 1)
green=$(tput setaf 2)
reset=$(tput sgr0)
export PS1="\[$green\]--=[$(date +%Y-%m-%d) \t @\[$reset\]\[$red\]\u\[$reset\]\[$green\]]=--\[$reset\]\n\w>"
 
 
# Keep track of all your command lines in ~/.bash_eternal_history file forever.
export HISTTIMEFORMAT="%s "
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER \
               "$(history 1)" >> ~/.bash_eternal_history'

Restarting the Shell Environment After Changes

source .bashrc

Reference: http://www.funtoo.org/Prompt_Magic

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.