-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathenvironment.conf
82 lines (67 loc) · 2.47 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
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
[ -n "$PS1" ] && bind "set completion-ignore-case on"
export RSYNC_RSH="ssh"
alias rsync='rsync -v --progress --partial'
alias less="less -R"
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.
if [[ ! $PROMPT_COMMAND =~ store_exit_status ]]; then
export PROMPT_COMMAND="store_exit_status && ${PROMPT_COMMAND:-:}"
fi
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
local last_commit
branch_prompt=$(__git_ps1 " (${COLOR_YELLOW}%s${COLOR_NONE})")
last_commit="${COLOR_WHITE}$(relative_time_since_last_commit)${COLOR_NONE}"
if [[ -n "$branch_prompt" ]]; then
echo "$branch_prompt $(show_git_status) $last_commit"
fi
fi
}
# Show a unicode character representing your current ruby VM.
show_rvm_prompt() {
local rvm_char
if [ -x "${HOME}/.rvm/bin/rvm-prompt" ]; then
rvm_char=`${HOME}/.rvm/bin/rvm-prompt u 2>/dev/null`
[ -n "${rvm_char}" ] && echo "${rvm_char} "
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}"
}
function relative_time_since_last_commit {
last_commit=`git log --pretty=format:'%ar' -1`
echo ${last_commit}
}
# Set PS1 from a prompt command so we can do both dynamic and
# non-printed sequences
set_ps1() {
PS1="\n$(show_rvm_prompt)$(show_time) $(prompt_color)\u@\h${COLOR_NONE}: ${COLOR_CYAN}\w${COLOR_NONE}$(show_exit_status)$(show_git_branch_and_status)\n> "
}
echo $PROMPT_COMMAND | grep -q ';\s*$' || PROMPT_COMMAND="${PROMPT_COMMAND:-:};"
PROMPT_COMMAND="${PROMPT_COMMAND:-:} set_ps1"