-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path.bash_profile
159 lines (138 loc) · 4.8 KB
/
.bash_profile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#Bash profile to change the default terminal prompt and add some git information.
#David Barnes
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
export TERM=xterm-color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Color shortcuts
export RESET_COLOR='\e[0m' # No Color
export BBLACK='\e[0;30m'
export BRED='\e[1;31m'
export BGREEN='\e[1;32m'
export BYELLOW='\e[1;33m'
export BBLUE='\e[1;34m'
export BPURPLE='\e[1;35m'
export BCYAN='\e[1;36m'
export BWHITE='\e[0;37m'
export BLACK='\e[0;30m'
export RED='\e[0;31m'
export GREEN='\e[0;32m'
export YELLOW='\e[0;33m'
export BLUE='\e[0;34m'
export PURPLE='\e[0;35m'
export CYAN='\e[0;36m'
export WHITE='\e[0;37m'
# Format for git_prompt_status()
BASH_THEME_GIT_PROMPT_UNMERGED=" $RED unmerged"
BASH_THEME_GIT_PROMPT_DELETED=" $RED deleted"
BASH_THEME_GIT_PROMPT_RENAMED=" $YELLOW renamed"
BASH_THEME_GIT_PROMPT_MODIFIED=" $YELLOW modified"
BASH_THEME_GIT_PROMPT_ADDED=" $GREEN added"
BASH_THEME_GIT_PROMPT_UNTRACKED=" $WHITE untracked"
BASH_THEME_GIT_PROMPT_PREFIX="$RESET_COLOR $CYAN"
BASH_THEME_GIT_PROMPT_SUFFIX="$RESET_COLOR"
BASH_THEME_GIT_PROMPT_DIRTY="$BRED (*)$RESET_COLOR"
BASH_THEME_GIT_PROMPT_CLEAN=""
# Colors vary depending on time lapsed.
BASH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="$GREEN"
BASH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="$BYELLOW"
BASH_THEME_GIT_TIME_SINCE_COMMIT_LONG="$BRED"
BASH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="$CYAN"
# Format for git_prompt_ahead()
BASH_THEME_GIT_PROMPT_AHEAD=" ${BWHITE}(${BYELLOW}↑${BWHITE})"
# Format for git_prompt_long_sha() and git_prompt_short_sha()
BASH_THEME_GIT_PROMPT_SHA_BEFORE="$YELLOW::$BLUE"
BASH_THEME_GIT_PROMPT_SHA_AFTER="$WHITE"
current_branch () {
local ref
ref=$(git symbolic-ref --quiet HEAD 2> /dev/null)
local ret="$?"
if [[ $ret != 0 ]]; then
[[ $ret == 128 ]] && return
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
fi
echo ${ref#refs/heads/}
}
# Outputs if current branch is ahead of remote
git_prompt_ahead () {
if [[ -n "$(git rev-list origin/$(current_branch)..HEAD 2> /dev/null)" ]]; then
echo "$BASH_THEME_GIT_PROMPT_AHEAD"
fi
}
# Checks if working tree is dirty
parse_git_dirty () {
local STATUS=''
local FLAGS
FLAGS=('--porcelain')
if [[ "$(git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
if [[ $POST_1_7_2_GIT -gt 0 ]]; then
FLAGS+='--ignore-submodules=dirty'
fi
if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then
FLAGS+='--untracked-files=no'
fi
STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1)
fi
if [[ -n $STATUS ]]; then
echo "$BASH_THEME_GIT_PROMPT_DIRTY"
else
echo "$BASH_THEME_GIT_PROMPT_CLEAN"
fi
}
# Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time.
git_time_since_commit () {
if git rev-parse --git-dir > /dev/null 2>&1; then
# Only proceed if there is actually a commit.
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# Get the last commit.
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
now=`date +%s`
seconds_since_last_commit=$((now-last_commit))
# Totals
MINUTES=$((seconds_since_last_commit / 60))
HOURS=$((seconds_since_last_commit/3600))
# Sub-hours and sub-minutes
DAYS=$((seconds_since_last_commit / 86400))
SUB_HOURS=$((HOURS % 24))
SUB_MINUTES=$((MINUTES % 60))
if [[ -n $(git status -s 2> /dev/null) ]]; then
if [ "$MINUTES" -gt 30 ]; then
COLOR="$BASH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
elif [ "$MINUTES" -gt 10 ]; then
COLOR="$BASH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
else
COLOR="$BASH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
fi
else
COLOR="$BASH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
fi
if [ "$HOURS" -gt 24 ]; then
echo "${COLOR}${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m${RESET_COLOR}"
elif [ "${MINUTES}" -gt 60 ]; then
echo "$COLOR${HOURS}h${SUB_MINUTES}m${RESET_COLOR}"
else
echo "$COLOR${MINUTES}m${RESET_COLOR}"
fi
else
COLOR="${BASH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL}"
echo "${RESET_COLOR}"
fi
fi
}
my_git_time () {
echo "$RESET_COLOR (${RESET_COLOR}`git_time_since_commit`${RESET_COLOR})"
}
color_prompt=yes;
force_color_prompt=yes;
# old pos was after current_branch for... $(git_prompt_short_sha)
# old pos was before dirty status for...$(git_prompt_status)
git_custom_status () {
local cb=$(current_branch)
if [ -n "$cb" ]; then
echo -e "${RESET_COLOR} on ${BASH_THEME_GIT_PROMPT_PREFIX}`current_branch`${BASH_THEME_GIT_PROMPT_SUFFIX}`my_git_time``parse_git_dirty``git_prompt_ahead`"
fi
}
PS1="\[$GREEN\]\u \[$RESET_COLOR\]at \[$YELLOW\]\h \[$RESET_COLOR\]in \[$BBLUE\]\w"'`git_custom_status`'" \n\[$CYAN\]> \[$RESET_COLOR\]"