Last active
December 20, 2015 03:29
-
-
Save stuartf/6064395 to your computer and use it in GitHub Desktop.
Awesome bash prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
hostnam=$(hostname) | |
usernam=$(whoami) | |
temp="$(tty)" | |
# Chop off the first five chars of tty (ie /dev/): | |
cur_tty="${temp:5}" | |
unset temp | |
function prompt_command { | |
LASTSTATUS="$?" | |
if (( $LASTSTATUS > 0 )) | |
then | |
LASTCOLOR=$(tput setaf 1; tput bold) | |
LASTSTATUS="☠" | |
else | |
LASTCOLOR=$(tput setaf 2; tput bold) | |
LASTSTATUS="✓" | |
fi | |
git_br=$(__git_ps1 "(%s)") | |
git_br=${git_br:1:-1} | |
if (( ${#git_br} > 0 )) | |
then | |
git_br_pre="┤" | |
git_br_post_color=$(tput setaf 6; tput bold) | |
git_br_post="├─" | |
else | |
git_br_pre="─" | |
git_br_post_color=$(tput setaf 4; tput bold) | |
git_br_post="──" | |
fi | |
# Find the width of the prompt: | |
TERMWIDTH=${COLUMNS} | |
# Add all the accessories below ... | |
local temp="──┤${usernam}@${hostnam}:${cur_tty}├───┤${PWD}├┤$git_br├──" | |
let fillsize=${TERMWIDTH}-${#temp} | |
if [ "$fillsize" -gt "0" ] | |
then | |
fill="───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────" | |
# It's theoretically possible someone could need more | |
# dashes than above, but very unlikely! HOWTO users, | |
# the above should be ONE LINE, it may not cut and | |
# paste properly | |
fill="${fill:0:${fillsize}}" | |
newPWD="${PWD}" | |
fi | |
if [ "$fillsize" -lt "0" ] | |
then | |
fill="" | |
let cut=3-${fillsize} | |
newPWD="...${PWD:${cut}}" | |
fi | |
} | |
PROMPT_COMMAND=prompt_command | |
function twtty { | |
local WHITE="\[$(tput setaf 7; tput bold)\]" | |
local NO_COLOUR="\[\033[0m\]" | |
local LIGHT_BLUE="\[$(tput setaf 6; tput bold)\]" | |
local BLUE="\[$(tput setaf 4; tput bold)\]" | |
local YELLOW="\[$(tput setaf 3; tput bold)\]" | |
local RED="\[$(tput setaf 1; tput bold)\]" | |
local GREEN="\[$(tput setaf 2; tput bold)\]" | |
case $TERM in | |
xterm*|rxvt*) | |
TITLEBAR='\[\033]0;\u@\h:\w\007\]' | |
;; | |
*) | |
TITLEBAR="" | |
;; | |
esac | |
if [[ $usernam == 'root' ]] | |
then | |
USERCOLOR=$RED | |
else | |
USERCOLOR=$BLUE | |
fi | |
PS1="${TITLEBAR}\ | |
${BLUE}─${LIGHT_BLUE}─┤\ | |
${USERCOLOR}\${usernam}${LIGHT_BLUE}@${YELLOW}\${hostnam}${LIGHT_BLUE}:${WHITE}\${cur_tty}\ | |
${LIGHT_BLUE}├─${BLUE}─\${fill}${LIGHT_BLUE}─┤\ | |
${BLUE}\${newPWD}\ | |
${LIGHT_BLUE}├\${git_br_pre}${YELLOW}\${git_br}\[\${git_br_post_color}\]\${git_br_post}${BLUE}─\ | |
\n\ | |
${BLUE}─${LIGHT_BLUE}─┤\ | |
${BLUE}\$(date +%H%M)${LIGHT_BLUE}:${BLUE}\$(date \"+%a,%d %b %y\")\ | |
${LIGHT_BLUE}:${WHITE}\[\${LASTCOLOR}\]\${LASTSTATUS}${LIGHT_BLUE}├─\ | |
${BLUE}─\ | |
${NO_COLOUR} " | |
PS2="${BLUE}─${LIGHT_BLUE}─┼─${BLUE}─${NO_COLOUR} " | |
} | |
twtty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment