Created
October 30, 2011 19:46
-
-
Save RSully/1326339 to your computer and use it in GitHub Desktop.
My basherc file
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
# If not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
export EDITOR='mate' | |
export GIT_EDITOR='mate -wl1' | |
## Aliases | |
# alias ls="ls --color=always" | |
alias ls="ls -G" | |
alias ll="ls -l -h" | |
alias la="ls -a" | |
alias l="ls" | |
alias lla="ls -a -l" | |
alias lm='ls -la | less' | |
alias cls='clear' | |
alias delpyc="find . -name '*.pyc' -delete" | |
alias tree='tree -Ca -I ".git|.svn|*.pyc|*.swp"' | |
alias sizes='du -h -d1' | |
alias airport='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport' | |
alias flushdns="dscacheutil -flushcache" | |
## Custom prompt | |
# Colors | |
RED="\[\033[0;31m\]" | |
PINK="\[\033[1;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[0;32m\]" | |
LT_GREEN="\[\033[1;32m\]" | |
BLUE="\[\033[0;34m\]" | |
WHITE="\[\033[1;37m\]" | |
PURPLE="\[\033[1;35m\]" | |
CYAN="\[\033[1;36m\]" | |
BROWN="\[\033[0;33m\]" | |
COLOR_NONE="\[\033[0m\]" | |
LIGHTNING_BOLT="⚡" | |
UP_ARROW="↑" | |
DOWN_ARROW="↓" | |
UD_ARROW="↕" | |
FF_ARROW="→" | |
RECYCLE="♺" | |
MIDDOT="•" | |
PLUSMINUS="±" | |
function parse_git_branch { | |
branch_pattern="^# On branch ([^${IFS}]*)" | |
remote_pattern_ahead="# Your branch is ahead of" | |
remote_pattern_behind="# Your branch is behind" | |
remote_pattern_ff="# Your branch (.*) can be fast-forwarded." | |
diverge_pattern="# Your branch and (.*) have diverged" | |
git_status="$(git status 2> /dev/null)" | |
if [[ ! ${git_status} =~ ${branch_pattern} ]]; then | |
# Rebasing? | |
toplevel=$(git rev-parse --show-toplevel 2> /dev/null) | |
[[ -z "$toplevel" ]] && return | |
[[ -d "$toplevel/.git/rebase-merge" || -d "$toplevel/.git/rebase-apply" ]] && { | |
sha_file="$toplevel/.git/rebase-merge/stopped-sha" | |
[[ -e "$sha_file" ]] && { | |
sha=`cat "${sha_file}"` | |
} | |
echo "${PINK}(rebase in progress)${COLOR_NONE} ${sha}" | |
} | |
return | |
fi | |
branch=${BASH_REMATCH[1]} | |
# Dirty? | |
if [[ ! ${git_status} =~ "working directory clean" ]]; then | |
[[ ${git_status} =~ "modified:" ]] && { | |
git_is_dirty="${RED}${LIGHTNING_BOLT}" | |
} | |
[[ ${git_status} =~ "Untracked files" ]] && { | |
git_is_dirty="${git_is_dirty}${WHITE}${MIDDOT}" | |
} | |
[[ ${git_status} =~ "new file:" ]] && { | |
git_is_dirty="${git_is_dirty}${LT_GREEN}+" | |
} | |
[[ ${git_status} =~ "deleted:" ]] && { | |
git_is_dirty="${git_is_dirty}${RED}-" | |
} | |
[[ ${git_status} =~ "renamed:" ]] && { | |
git_is_dirty="${git_is_dirty}${YELLOW}→" | |
} | |
fi | |
# Are we ahead of, beind, or diverged from the remote? | |
if [[ ${git_status} =~ ${remote_pattern_ahead} ]]; then | |
remote="${YELLOW}${UP_ARROW}" | |
elif [[ ${git_status} =~ ${remote_pattern_ff} ]]; then | |
remote_ff="${WHITE}${FF_ARROW}" | |
elif [[ ${git_status} =~ ${remote_pattern_behind} ]]; then | |
remote="${YELLOW}${DOWN_ARROW}" | |
elif [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="${YELLOW}${UD_ARROW}" | |
fi | |
echo "${remote}${remote_ff}${GREEN}(${branch})${COLOR_NONE}${git_is_dirty}${COLOR_NONE}" | |
} | |
function set_prompt { | |
# [[ -n $HOMEBREW_DEBUG_INSTALL ]] && \ | |
# homebrew_prompt="${BROWN}Homebrew:${COLOR_NONE} debugging ${HOMEBREW_DEBUG_INSTALL}\n" | |
# git_prompt="$(parse_git_branch)" | |
# export PS1="[\w] ${git_prompt}${COLOR_NONE}\n${homebrew_prompt}\$ " | |
export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
} | |
export PROMPT_COMMAND=set_prompt | |
# Open a manpage in Preview, which can be saved to PDF | |
function pman { | |
man -t "${1}" | open -f -a /Applications/Preview.app | |
} | |
# Open a manpage in the browser | |
function bman { | |
man "${1}" | man2html | browser | |
} | |
function pgrep { | |
local exclude="\.svn|\.git|\.swp|\.coverage|\.pyc|_build" | |
find . -maxdepth 1 -mindepth 1 | egrep -v "$exclude" | xargs egrep -lir "$1" | egrep -v "$exclude" | xargs egrep -Hin --color "$1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment