My ~/.bashrc
This file contains 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
green=$(tput setaf 2) | |
yellow=$(tput setaf 3) | |
magenta=$(tput setaf 5) | |
reset=$(tput sgr0) | |
# This was not working with \w, which has since been changed to \W in favor of window title showing $PWD | |
# PROMPT_DIRTRIM=3 | |
export EDITOR='code --wait'; | |
export SVN_EDITOR='code --wait'; | |
### TEST STUFF ### | |
### ALIASES ### | |
alias bashrc='code ~/.bashrc -w && source ~/.bashrc' | |
alias hosts='code /etc/hosts' | |
alias ls='ls -1AFG' | |
alias la='ls -hlo' | |
alias o='open .' | |
alias sshkey='cat ~/.ssh/id_rsa.pub | pbcopy' | |
alias sshhhs='ssh helenhou@helenhousandi.com -p18765' | |
alias sshwporg='ssh -ND 8080 -p22 helen@proxy.wordpress.org' | |
alias sphp='/usr/local/bin/sphp-osx/sphp' | |
alias fix10upbot='heroku ps:scale hubot=0 && heroku ps:scale hubot=1' | |
alias plugin-deploy='sh ~/Dropbox/cli/plugin-deploy/plugin-deploy.sh' | |
alias plugin-tag='sh ~/Dropbox/cli/plugin-deploy/plugin-tag.sh' | |
# VVV | |
vvvlink() { | |
ln -s /srv/www/sites/$1 $1 | |
} | |
# SVN | |
alias a='sh ~/Dropbox/cli/attach-patch.sh' | |
alias sd='svn diff > /tmp/svn.diff && code /tmp/svn.diff' | |
alias sr=svnclean | |
alias sup='svn up --ignore-externals' | |
mod() { | |
svn stat --ignore-externals | grep '^[^?X]' | |
} | |
red() { | |
svn diff | ack "^[-|\+]" -oh | sort | uniq -c | ack [0-9]+ -oh | xargs | awk '{print $1 - $2}' | |
} | |
svnstash() { | |
svn diff > ~/Desktop/$1.diff | |
} | |
svnclean() { | |
svn revert -R * && find . -name "*.orig" -delete && find . -name "*.rej" -delete && sup | |
} | |
tp() { | |
#curl "$1?format=raw" | /usr/bin/patch -p0 | |
grunt patch:$1 | |
} | |
# GIT | |
alias ahead='git log origin/master..HEAD' | |
# alias gd='git diff | code -' | |
alias gd='git diff > /tmp/git.diff && code /tmp/git.diff --wait' | |
alias gp='git pull' | |
alias gpr='git pull --rebase' | |
alias gr='git reset --hard HEAD' | |
alias gs='git status' | |
### PROMPT ### | |
# I am not convinced this is always working correctly. | |
export PROMPT_DIRTRIM=3 | |
parse_svn_revision() { | |
local BRANCH INFO=$(svn info 2>/dev/null) | |
[ "$INFO" ] || return | |
REV=$(printf "%s\n" "$INFO" | grep Revision | sed -e 's/Revision: //') | |
BRANCH=$(printf "%s\n" "$INFO" | grep ^URL | sed -e 's/URL: //' | xargs basename) | |
printf "${BRANCH}:r${REV}" | |
} | |
svn_local_changes() { | |
local DIRTY INFO=$(svn info 2>/dev/null) | |
[ "$INFO" ] || return | |
[ "$(svn stat --ignore-externals | grep -v [X?])" ] && DIRTY=' * ' | |
printf "$DIRTY" | |
} | |
# get current branch in git repo | |
parse_git_branch() { | |
# SVN checkouts inside Git repos, cough VVV | |
local SVN=$(svn info 2>/dev/null) | |
[ ! "$SVN" ] || return | |
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) | |
[ "$BRANCH" ] || return | |
STAT=$(parse_git_dirty) | |
printf "[${BRANCH}\001${green}\002${STAT}\001${magenta}\002]" | |
} | |
# get current status of git repo | |
parse_git_dirty() { | |
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) | |
REMOTE=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2>/dev/null) | |
if [ "$REMOTE" ]; then | |
FETCH=$(printf "$REMOTE" | sed 's!/! !') | |
git fetch $FETCH &>/dev/null | |
BEHIND=$(git rev-list "${BRANCH}..${REMOTE}" --count 2>/dev/null) | |
AHEAD=$(git rev-list "${REMOTE}..${BRANCH}" --count 2>/dev/null) | |
else | |
# If there is no remote (i.e. local branch), | |
# show how many commits since this was branched off. | |
PREV=$(git show-branch 2>/dev/null | ack '\!' | ack -v "$BRANCH" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//') | |
# The above is having something go weird and I basically always branch off master so let's just be lazy for now | |
# PREV="master" | |
AHEAD=$(git rev-list "${PREV}..${BRANCH}" --count 2>/dev/null) | |
BEHIND=0 | |
fi | |
# This is still from whatever the original source was, | |
# I am not sure I like this method but it will do for now. | |
STATUS=$(git status 2>&1 | tee) | |
DIRTY=$(printf "${STATUS}" 2> /dev/null | grep "modified:" &> /dev/null; printf "$?") | |
UNTRACKED=$(printf "${STATUS}" 2> /dev/null | grep "Untracked files" &> /dev/null; printf "$?") | |
NEWFILE=$(printf "${STATUS}" 2> /dev/null | grep "new file:" &> /dev/null; printf "$?") | |
RENAMED=$(printf "${STATUS}" 2> /dev/null | grep "renamed:" &> /dev/null; printf "$?") | |
DELETED=$(printf "${STATUS}" 2> /dev/null | grep "deleted:" &> /dev/null; printf "$?") | |
BITS='' | |
if [ "${DIRTY}" == "0" ]; then | |
BITS="*${BITS}" | |
fi | |
if [ "${RENAMED}" == "0" ]; then | |
BITS=">${BITS}" | |
fi | |
if [ "${AHEAD}" -gt "0" ]; then | |
BITS="↑\001${reset}\002${AHEAD}\001${green}\002${BITS}" | |
fi | |
if [ "${BEHIND}" -gt "0" ]; then | |
BITS="↓\001${reset}\002${BEHIND}\001${green}\002${BITS}" | |
fi | |
if [ "${NEWFILE}" == "0" ]; then | |
BITS="+${BITS}" | |
fi | |
if [ "${UNTRACKED}" == "0" ]; then | |
BITS="?${BITS}" | |
fi | |
if [ "${DELETED}" == "0" ]; then | |
BITS="x${BITS}" | |
fi | |
if [ ! "${BITS}" == "" ]; then | |
printf " ${BITS}" | |
else | |
printf "" | |
fi | |
} | |
set_bash_prompt() { | |
# Working directory in the tab / window | |
# Not necessary in Terminal anymore, but still needed in iTerm, etc. | |
# Tab name (1) - working directory | |
echo -ne "\033]1;${PWD##*/}\007" | |
# Window name (2) - full path | |
echo -ne "\033]2;$PWD\007" | |
# ❄️ 👑 | |
# The variation sequence needs to be indicated as non-printing for length | |
# or else you get fun wrapping problems. | |
# Octals just make it easier to see instead of pasting an invisible character. | |
# Octals and variant detection from http://graphemica.com/ | |
CROWN="\360\237\221\221" | |
SNOW="\342\235\204" | |
VARIANT="\357\270\217" | |
PS1="${SNOW}\[${VARIANT}\] ${CROWN} \[${yellow}\]\W \[${magenta}\]\$(parse_svn_revision)\$(parse_git_branch)\[${green}\]\$(svn_local_changes)\[${reset}\]$ " | |
} | |
# This prompt still has some kind of length issue; | |
# manifests when you cycle past a long history entry. | |
PROMPT_COMMAND="set_bash_prompt; $PROMPT_COMMAND" | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh | |
# [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion | |
source ~/Dropbox/cli/git-completion.bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment