Skip to content

Instantly share code, notes, and snippets.

@kentquirk
Last active August 29, 2015 14:21
Show Gist options
  • Save kentquirk/9820348e451da9fc02b4 to your computer and use it in GitHub Desktop.
Save kentquirk/9820348e451da9fc02b4 to your computer and use it in GitHub Desktop.
a starter version of .bash_profile for new machines
# this is extra bash stuff to make things easier to manage
shopt -s histappend
HISTFILESIZE=2000
HISTSIZE=1000
export TERM=xterm-256color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
alias grep='grep --color=auto'
# what are my local ips
alias ips="ifconfig -a |tr '[a-zA-Z] ' '\n' |egrep '\d+\.\d+\.\d+\.\d+'"
# what's my external ip
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
#################################################################
# Here's a bunch of stuff to do prompts that are sensitive to git
# sets the title of the iterm2 window
title()
{
TITLE=$*;
export PROMPT_COMMAND='echo -ne "\033]0;$TITLE\007"'
}
# sets the title of iterm2 to the current directory tail
titledir()
{
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
}
titledir
WHT='\e[22;37m'
TEAL='\e[22;36m'
BLK='\e[22;30m'
RED='\e[22;31m'
GRN='\e[22;32m'
YEL='\e[22;33m'
BLU='\e[22;34m'
BRED='\e[1;31m'
BGRN='\e[1;32m'
BYEL='\e[1;33m'
BBLU='\e[1;34m'
BWHT='\e[1;37m'
BBLK='\e[1;30m'
BGBLK='\e[40m'
BGBLU='\e[44m'
BGYEL='\e[43m'
BGWHT='\e[47m'
BGRED='\e[41m'
KILLCOLOR='\e[0m'
TIME='\@'
USER='\u'
HOST='\h'
WORKINGDIR='\w'
CLR_FRAME=$TEAL
CLR_DIR=$WHT
CLR_GIT=$BYEL
CLR_TIME=$BWHT
CLR_BG=$BGBLU
CLR_VENV=$YEL
parse_git_branch() {
#git branch | grep \* | sed 's/* //'
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_svn_revision() {
svn info 2>/dev/null | grep "Revision: "| cut -d ' ' -f 2
}
get_revision() {
if [ -e .git ]; then
parse_git_branch
else
parse_svn_revision
fi
}
get_venv() {
if [ ! -z $VIRTUAL_ENV ]; then
echo " ($(basename $VIRTUAL_ENV))"
fi
}
# Only do a color prompt if we actually want color
case "$TERM" in
xterm-256color)
PS1="$CLR_BG $CLR_FRAME[$CLR_TIME$TIME$CLR_FRAME][$CLR_DIR$WORKINGDIR$CLR_VENV\$(get_venv)$CLR_FRAME][$CLR_GIT\$(get_revision)$CLR_FRAME] $KILLCOLOR\n\$ "
;;
*)
PS1="[ $TIME ][ $WORKINGDIR \$(get_venv) ][ \$(get_revision) ] \n\$ "
;;
esac
#################################################################
#######################
# some find helpers
findinsource() {
find . \( -iname "*.py" -or -iname "*.[ch]" -or -iname "*.cpp" -or -iname "*.js" -or -iname "*.cs" -or -iname "*.go" \) -print0 |xargs -0 grep "$@"
}
findinpycode() {
find $CODE -name "*.py" -print0 |xargs -0 grep "$@"
}
editpyfileswith() {
find $CODE -name "*.py" -print0 |xargs -0 grep --files-with-matches "$@" |xargs subl
}
########################
# some git helpers
whatwillipush() {
git log --no-merges --pretty=format:"%h %Cblue%cn %Cred%s" $(parse_git_branch) ^origin/$(parse_git_branch)
}
diffcommit() {
git diff $1^ $1
}
branchdates() {
for k in `git branch -a | grep -v \> | sed s/^..//`; do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k --`\\t"$k";done | sort
}
alltags() {
git tag | egrep "v[0-9]+\.[0-9]+\.[0-9]+(-.+)?" |tr '.-' ' *' |sort --numeric-sort --key 1.1 --key 2 --key 3 |tr ' *' '.-'
}
lasttag() {
alltags |tail -1
}
gitlog1() {
git log --max-count 1 --pretty=oneline --abbrev-commit --no-merges $1
}
resync_master()
{
git checkout master
git fetch --prune --tags
git pull origin master
}
########################
# sometimes I like a command line calculator
# this removes all the non-calculation stuff from a line and passes it to bc
function calc() {
equat=$(echo ${@//[^0-9\.\+\/\*\(\)\^]/ }| sed 's/[ \t]*//g')
echo $equat|bc -lq
}
########################
# Simple web server for current directory on port 8000 (can be overridden)
function simpleserver()
{
echo IP: `ipconfig getifaddr en0`
port=8000
if [ "$1" != "" ]; then
port=$1
fi
python -m SimpleHTTPServer $port
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment