Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (67 sloc) 2.47 KB
[ -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"