Skip to content

Instantly share code, notes, and snippets.

@b1zzu
Last active November 27, 2017 17:19
Show Gist options
  • Save b1zzu/23fcd8066d3711292f0beb8cdf5baf25 to your computer and use it in GitHub Desktop.
Save b1zzu/23fcd8066d3711292f0beb8cdf5baf25 to your computer and use it in GitHub Desktop.
Bash Theme
# davbizz prompt script
# vim:set syntax=sh:
# Inspired by https://github.com/demure/dotfiles/blob/master/subbash/prompt
# Install:
# 1. Copy/Checkout this file in your home directory
# 2. Install powerline fonts and set a powerline font for your terminal ( https://github.com/powerline/fonts )
# 3. Include this file from the .bashrc ( . $HOME/.bash_theme )
#
# Depending on the additional PROMPT_COMMAND you have the include of the .bash_theme could
# be in a different position in your .bashrc file
#
# If you have debina/ubuntu or derivate distro you can install powerline fonts using apt
# apt install fonts-powerline
function __prompt_command() {
# This needs to be the first
local EXIT="$?"
PS1=""
local Reset='\[\e[0m\]'
local Black='\[\e[90m\]'
local Red='\[\e[31m\]'
local Green='\[\e[32m\]'
local Blue='\[\e[34m\]'
local White='\[\e[97m\]'
local Gray='\[\e[37m\]'
local BgBlack='\[\e[100m\]'
local BgRed='\[\e[41m\]'
local BgGreen='\[\e[42m\]'
local BgBlue='\[\e[44m\]'
local BgNone='\[\e[49m\]'
local Triangle=$'\xee\x82\xb0'
local Arrow=$'\xee\x82\xb1'
# exit
if [[ "$EXIT" -eq "0" ]]; then
PS1+="${BgGreen}${White} ${EXIT} ${Green}"
else
PS1+="${BgRed}${White} ${EXIT} ${Red}"
fi
# hostname
PS1+="${BgBlack}${Triangle}${White} $(hostname) "
# dir
PS1+="${Gray}${Arrow}${White} $(dirs) ${Black}${BgNone}${Triangle}"
PS1+="\n"
# user
if [[ "$USER" == "root" ]]; then
# Use red for root user
PS1+="${White}${BgRed} ${USER} ${Red}${BgNone}${Triangle}"
PS2="${Red}${Arrow}${Reset}"
else
# Otherwise use blue
PS1+="${White}${BgBlue} ${USER} ${Blue}${BgNone}${Triangle}"
PS2="${Blue}${Arrow}${Reset}"
fi
# end
PS1+="${Reset} "
}
# This Changes The PS1
PROMPT_COMMAND="__prompt_command;$PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment