-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprompt.sh
55 lines (47 loc) · 1.2 KB
/
prompt.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
52
53
54
55
#!/bin/sh
red=$(tput setaf 1)
green=$(tput setaf 2)
normal=$(tput sgr0)
EDITED_BRANCH_COLOR=$red
CLEAN_BRANCH_COLOR=$green
NORMAL_COLOR=$normal
function parse_git_branch {
git status > /dev/null 2>&1
if [ $? == 0 ]; then
ref=$(git symbolic-ref --short HEAD 2> /dev/null) || return
echo -e " [${ref}]"
else
return
fi
}
function cleanliness_color {
git status > /dev/null 2>&1
if [ $? == 0 ]; then
version=$(git --version | awk '{print $3}' | tr '.' '\t' | awk '{print $2}')
if [ "${version}" -gt 8 ]; then
status=$(git status | sed -n '/\(working tree clean\)/p') || return
else
status=$(git status | sed -n '/\(working directory clean\)/p') || return
fi
if [ -n "${status}" ]; then
echo -e $CLEAN_BRANCH_COLOR
else
echo -e $EDITED_BRANCH_COLOR
fi
else
return
fi
}
function current_dir_name {
if [ "$PWD" == "$HOME" ]; then
echo -e "~"
else
echo -e "${PWD##*/}"
fi
}
function current_time {
echo -e $(date +%H:%M)
}
# This is the string that will be printed out to the console
PS1='\[${NORMAL_COLOR}\]`current_time` `whoami`\[$(cleanliness_color)\]`parse_git_branch`\[${NORMAL_COLOR}\] `current_dir_name`
👹✨🍕 '