forked from matschaffer/profile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
environment.conf
54 lines (44 loc) · 1.64 KB
/
environment.conf
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
bind "set completion-ignore-case on"
export RSYNC_RSH="ssh"
alias rsync='rsync -v --progress --partial'
export PYTHONSTARTUP="$HOME/.pythonrc.py"
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;32'
# Returns 0 (success) if the pwd is tracked, otherwise 1 (failure).
git_pwd_is_tracked() {
[ $(git log -1 --pretty=oneline . 2> /dev/null | wc -l) -eq "1" ]
}
# Emits the current time in 24-hr notation.
show_time() {
echo "${COLOR_GRAY}$(date +%H:%M)${COLOR_NONE}"
}
# Stores the exit status of the last command for use by show_exit_status function.
export PROMPT_COMMAND="store_exit_status"
store_exit_status() {
LAST_EXIT_STATUS=$?
}
# Emits exit status of last command if error condition returned.
show_exit_status() {
if [ "x${LAST_EXIT_STATUS}" != "x0" ]; then
echo " [${COLOR_RED}${LAST_EXIT_STATUS}${COLOR_NONE}]"
fi
}
# Emits the current git branch and marker if there are outstanding changes.
show_git_branch_and_status() {
if git_pwd_is_tracked; then
local branch_prompt
branch_prompt=$(__git_ps1 " (${COLOR_YELLOW}%s${COLOR_NONE})")
if [[ -n "$branch_prompt" ]]; then
echo "$branch_prompt $(show_git_status)"
fi
fi
}
# Removes display of git status from prompt, useful for large repositories.
hide_git_status() {
show_git_branch_and_status() { exit; }
}
# Emits a red ✗ if current repository is 'dirty'.
show_git_status() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "${COLOR_RED}変${COLOR_NONE}"
}
export PS1="\n"'$(show_time) $(prompt_color)'"\u@\h${COLOR_NONE}: ${COLOR_CYAN}\w${COLOR_NONE}"'$(show_exit_status)$(show_git_branch_and_status)'"\n> "