2020-11-06 14:24:10 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# see
|
|
|
|
# used http://bashrcgenerator.com/
|
|
|
|
# and
|
|
|
|
# https://unix.stackexchange.com/questions/148/colorizing-your-terminal-and-shell-environment/174#174
|
|
|
|
|
|
|
|
function parse_git_branch() {
|
|
|
|
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
|
|
|
|
}
|
|
|
|
|
|
|
|
function fancy_prompt () {
|
|
|
|
|
|
|
|
# if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
|
|
|
|
|
|
|
|
function c () {
|
|
|
|
local color
|
|
|
|
name=COLOR_$1
|
|
|
|
color=${!name}
|
|
|
|
echo '\['$color'\]'
|
|
|
|
}
|
|
|
|
|
|
|
|
case $TERM in
|
|
|
|
xterm*|rxvt*)
|
|
|
|
# local TITLEBAR='\[\033]0;\u ${NEW_PWD}\007\]'
|
|
|
|
local PARENTBASE='${PWD#"${PWD%/*/*}/"}'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local PARENTBASE=''
|
|
|
|
# local TITLEBAR=""
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
local UC=WHITE # user's color
|
2020-11-10 14:09:08 -08:00
|
|
|
[ $UID -eq "0" ] && UC=LIGHT_RED # root's color
|
2020-11-06 14:24:10 -08:00
|
|
|
|
|
|
|
# PS1="$PARENTBASE\[${UC}\]\u@\h: \[${COLOR_LIGHT_GREEN}\]→\[${COLOR_NC}\] "
|
|
|
|
|
|
|
|
local user
|
|
|
|
local machine
|
|
|
|
local dir
|
|
|
|
local branch
|
|
|
|
local promptc
|
|
|
|
user="$(c $UC)\u$(c GREY)@$(c NC)"
|
|
|
|
machine="$(c CYAN)\h$(c GREY):$(c NC)"
|
|
|
|
dir="$(c YELLOW)[${PARENTBASE}]$(c NC)"
|
|
|
|
branch=$(c LIGHT_BLUE)'$(parse_git_branch)'$(c NC)
|
|
|
|
promptc=$(c GREEN)' $ '$(c NC)
|
|
|
|
|
|
|
|
PS1=$(echo "$user$machine$dir$branch$promptc")
|
|
|
|
# echo $PS1
|
|
|
|
}
|
|
|
|
|
2020-11-10 14:09:08 -08:00
|
|
|
# fancy prompt is on by default comment out to disable default
|
2020-11-06 14:24:10 -08:00
|
|
|
fancy_prompt
|