-
Notifications
You must be signed in to change notification settings - Fork 1
/
.prompt2.sh
51 lines (50 loc) · 1.61 KB
/
.prompt2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
prompt_command () {
if [ $? -eq 0 ]; then # set an error string for the prompt, if applicable
ERRPROMPT=" "
else
ERRPROMPT='->($?) '
fi
if [ "\$(type -t __git_ps1)" ]; then # if we're in a Git repo, show current branch
BRANCH="\$(__git_ps1 '[ %s ] ')"
fi
local TIME=`fmt_time` # format time for prompt string
local LOAD=`uptime|awk '{min=NF-2;print $min}'`
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local BCYAN="\[\033[1;36m\]"
local BLUE="\[\033[0;34m\]"
local GRAY="\[\033[0;37m\]"
local DKGRAY="\[\033[1;30m\]"
local WHITE="\[\033[1;37m\]"
local RED="\[\033[0;31m\]"
# return color to Terminal setting for text color
local DEFAULT="\[\033[0;39m\]"
# set the titlebar to the last 2 fields of pwd
local TITLEBAR='\[\e]2;`pwdtail`\a'
export PS1="\[${TITLEBAR}\]${CYAN}[ ${BCYAN}\u${GREEN}@${BCYAN}\
\h${DKGRAY}(${LOAD}) ${WHITE}${TIME} ${CYAN}]${RED}$ERRPROMPT${GRAY}\
\w\n${GREEN}${BRANCH}${DEFAULT}$ "
}
PROMPT_COMMAND=prompt_command
fmt_time () { #format time just the way I likes it
if [ `date +%p` = "PM" ]; then
meridiem="pm"
else
meridiem="am"
fi
date +"%l:%M:%S$meridiem"|sed 's/ //g'
}
pwdtail () { #returns the last 2 fields of the working directory
pwd|awk -F/ '{nlast = NF -1;print $nlast"/"$NF}'
}
chkload () { #gets the current 1m avg CPU load
local CURRLOAD=`uptime|awk '{print $8}'`
if [ "$CURRLOAD" > "1" ]; then
local OUTP="HIGH"
elif [ "$CURRLOAD" < "1" ]; then
local OUTP="NORMAL"
else
local OUTP="UNKNOWN"
fi
echo $CURRLOAD
}