forked from denlab/stumpwm-config
-
Notifications
You must be signed in to change notification settings - Fork 6
/
.shrc-prompt
executable file
·69 lines (59 loc) · 1.81 KB
/
.shrc-prompt
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- sh -*-
# ~/.bash_prompt: executed by bashrc
# some intelligent method to set the prompt
prompt_command () {
RET=$?
if [ $RET -eq 0 ]; then # set an error string for the prompt, if applicable
ERRPROMPT=""
else
ERRPROMPT='($RET) '
fi
if [ "\$(type -t __git_ps1)" ]; then # if we're in a Git repo, show current branch
BRANCH=" \$(__git_ps1 '(%s) ')"
fi
# setup preferences
local TIME=`fmt_time` # format time for prompt string
local LOAD=`uptime|awk '{min=NF-2;print $min}'`
# set the titlebar to the last 2 fields of pwd
local TITLEBAR='\[\e]2;`pwdtail`\a\]'
# colors
local GREEN="\e[0;32m"
local DKGREEN="\e[1;32m"
local CYAN="\e[0;36m"
local DKCYAN="\e[1;36m"
local BLUE="\e[0;34m"
local DKBLUE="\e[1;34m"
local GRAY="\e[0;37m"
local DKGRAY="\e[1;30m"
local WHITE="\e[1;37m"
local RED="\e[0;31m"
local DKRED="\e[1;31m"
# return color to Terminal setting for text color
local DEFAULT="\e[0;39m"
# delete ${TITLEBAR} because it doesn't work inside the shell emacs or in the tty screen
export PS1="\n╭─${DKBLUE}\u${DKBLUE}@${DKBLUE}\
\h${DKCYAN}(${LOAD}) ${WHITE}${TIME} ${DKRED}$ERRPROMPT${DKBLUE}\
\w${DKGREEN}${BRANCH}${DEFAULT}\n╰─➤ ${DKBLUE} ${DEFAULT}"
export PS2=" ─➤ "
}
# Format time just the way I likes it
fmt_time () {
date +"%H:%M:%S"
}
# Returns the last 2 fields of the working directory
pwdtail () {
pwd|awk -F/ '{nlast = NF -1;print $nlast"/"$NF}'
}
# Gets the current 1m avg CPU load
chkload () {
local CURRLOAD=`uptime|awk '{print $8}'`
if [ "$CURRLOAD" -gt "1" ]; then
local OUTP="HIGH"
elif [ "$CURRLOAD" -lt "1" ]; then
local OUTP="NORMAL"
else
local OUTP="UNKNOWN"
fi
echo $CURRLOAD
}
PROMPT_COMMAND=prompt_command