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
|
|
|
|
|
2021-04-14 10:51:17 -07:00
|
|
|
|
2020-11-06 14:24:10 -08:00
|
|
|
local UC=WHITE # user's color
|
2021-04-14 10:51:17 -07:00
|
|
|
local MC=CYAN # machine color
|
|
|
|
[[ $SSH_SESSION == "true" ]] && UC=LIGHT_PURPLE && MC=WHITE # remote machine 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)"
|
2021-04-14 10:51:17 -07:00
|
|
|
machine="$(c $MC)\h$(c GREY):$(c NC)"
|
2020-11-06 14:24:10 -08:00
|
|
|
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
|