Created
June 29, 2015 11:47
-
-
Save cypreess/58876ac7cd87213b0aac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export HISTTIMEFORMAT='%F %T ' | |
export CLICOLOR="YES" | |
export LSCOLORS="Fxgxcxdxcxegedabagacad" | |
alias l="ls -lFoh" | |
alias la="ls -lFohA" | |
alias xclip='xclip -selection c' | |
alias grep="grep --color" | |
alias su="su -" | |
alias c="clear" | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
c_hour="\[$(tput setaf 2)\]" | |
c_user="\[$(tput setaf 100)\]" | |
c_host="\[$(tput setaf 3)\]" | |
c_path="\[$(tput setaf 5)$(tput bold)\]" | |
c_reset="\[$(tput sgr0)\]" | |
c_git_clean="\[$(tput setaf 2)\]" | |
c_git_to_commit="\[$(tput setaf 3)\]" | |
c_git_dirty="\[$(tput setaf 1)\]" | |
c_exit="\[$(tput setaf 1)$(tput bold)\]" | |
c_virtualenv="\[$(tput setaf 6)\]" | |
show_user(){ | |
if [ $USER == $MY_USERNAME ]; then | |
return 0 | |
fi | |
printf "${c_user}${USER}${c_host}@${c_reset}" | |
} | |
git_prompt(){ | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
return 0 | |
fi | |
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
if git diff --quiet HEAD 2>/dev/null >&2; then | |
git_color="${c_git_clean}" | |
elif git diff --quiet 2>/dev/null >&2; then | |
git_color="${c_git_to_commit}" | |
else | |
git_color="${c_git_dirty}" | |
fi | |
echo "${c_reset}${git_color}[${git_branch}]${c_reset}" | |
} | |
set_bash_prompt(){ | |
#exit_code=$? | |
VIRTUAL_ENV_NAME=`basename "$VIRTUAL_ENV"` | |
if [ $exit_code -ne 0 ]; then | |
exit_code="${c_exit}! ${exit_code}${c_reset}\n" | |
else | |
exit_code="" | |
fi | |
if [ ! $VIRTUAL_ENV_NAME == '' ]; then | |
VIRTUAL_ENV_NAME="${c_reset}${c_virtualenv}($VIRTUAL_ENV_NAME)${c_reset}" | |
else | |
VIRTUAL_ENV_NAME= | |
fi | |
# Run only on linux box | |
if [ $OSTYPE == 'linux-gnu' ]; then | |
if [ $NOTIFY_CMD -eq 1 ]; then | |
notify-send "Command exited" | |
fi | |
fi | |
PS1="${exit_code}${c_hour}\A${c_reset} ${VIRTUAL_ENV_NAME}$(show_user)${c_reset}${c_host}\h$(git_prompt)${c_reset}${c_path}\w${c_reset} " | |
} | |
log_bash_persistent_history() | |
{ | |
[[ | |
$(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$ | |
]] | |
local date_part="${BASH_REMATCH[1]}" | |
local command_part="${BASH_REMATCH[2]}" | |
if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ] | |
then | |
echo $date_part$'\t'"$command_part" >> ~/.history_persistent | |
export PERSISTENT_HISTORY_LAST="$command_part" | |
fi | |
} | |
# Stuff to do on PROMPT_COMMAND | |
run_on_prompt_command() | |
{ | |
exit_code=$? | |
log_bash_persistent_history | |
set_bash_prompt | |
} | |
PROMPT_COMMAND=run_on_prompt_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment