Created
December 7, 2017 01:49
-
-
Save kentquirk/3797f1fd4249d45d8fb21ae2f43ff825 to your computer and use it in GitHub Desktop.
sanitized_bash_profile
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 JAVA_HOME="$(/usr/libexec/java_home)" | |
export ANDROID_HOME=/usr/local/opt/android-sdk | |
export GOPATH=$HOME/go | |
export PATH_FIRST=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${JAVA_HOME} | |
export PATH_LAST=/usr/local/opt/go/libexec/bin:$GOPATH/bin | |
export PATH=$(fixpath.py) | |
export PATH_FIRST= | |
export PATH_LAST= | |
shopt -s histappend | |
HISTFILESIZE=10000 | |
HISTSIZE=5000 | |
export TERM=xterm-256color | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxCxDxBxegedabagacad | |
export EDITOR="subl -w" | |
export CODE=~/code | |
# crazy-ass bash completion scripts | |
if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
. $(brew --prefix)/etc/bash_completion | |
fi | |
# for working with virtualenv | |
activate() { | |
ACT=$(find . -depth 3 -name "activate") | |
if [ ! -z $ACT ]; then | |
VIRTUAL_ENV_DISABLE_PROMPT=true | |
source $ACT | |
else | |
echo "No virtualenv in this folder." | |
fi | |
} | |
alias sub='subl' | |
alias grep='grep --color=auto' | |
alias fn='find . -name' | |
alias vc='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron' | |
# 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" | |
# flush DNS cache | |
alias flushdns="dscacheutil -flushcache" # Flush DNS cache | |
alias gotest='go test -race -v $(glide novendor)' | |
################################################################# | |
# Here's a bunch of stuff to do prompts that are sensitive to git and svn | |
# 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"' | |
} | |
# dark color component | |
dcc() | |
{ | |
jot -nr 1 20 120 | |
} | |
# light color component | |
lcc() | |
{ | |
jot -nr 1 130 255 | |
} | |
rndDarkBg() | |
{ | |
echo '\e[48;2;$(dcc);$(dcc);$(dcc)m' | |
} | |
rndLightFg() | |
{ | |
echo '\e[38;2;$(lcc);$(lcc);$(lcc)m' | |
} | |
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' | |
MAG='\e[22;35m' | |
CYN='\e[22;36m' | |
BRED='\e[1;31m' | |
BGRN='\e[1;32m' | |
BYEL='\e[1;33m' | |
BBLU='\e[1;34m' | |
BMAG='\e[1;35m' | |
BCYN='\e[1;36m' | |
BWHT='\e[1;37m' | |
BBLK='\e[1;30m' | |
BGBLK='\e[40m' | |
BGRED='\e[41m' | |
BGGRN='\e[42m' | |
BGYEL='\e[43m' | |
BGBLU='\e[44m' | |
BGMAG='\e[45m' | |
BGCYN='\e[46m' | |
BGWHT='\e[47m' | |
KILLCOLOR='\e[0m' | |
CLEAREOL='\e[K' | |
TIME='\@' | |
USER='\u' | |
HOST='\h' | |
WORKINGDIR='\w' | |
CLR_FRAME=$WHT | |
CLR_DIR=$BRED | |
CLR_GIT=$BYEL | |
CLR_TIME=$BWHT | |
CLR_BG=$BGBLU | |
CLR_VENV=$GRN | |
parse_git_branch() { | |
git symbolic-ref --short HEAD 2> /dev/null | |
} | |
parse_svn_revision() { | |
svn info 2>/dev/null | grep "Revision: "| cut -d ' ' -f 2 | |
} | |
get_revision() { | |
svn info >/dev/null 2>&1 && parse_svn_revision || parse_git_branch | |
} | |
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="$(rndDarkBg) $CLR_FRAME[$(rndLightFg)$TIME$CLR_FRAME][$(rndLightFg)$WORKINGDIR$(rndLightFg)\$(get_venv)$CLR_FRAME][$(rndLightFg)\$(get_revision)$CLR_FRAME] $CLEAREOL$KILLCOLOR\n\$ " | |
;; | |
*) | |
PS1="[ $TIME ][ $WORKINGDIR \$(get_venv) ][ \$(get_revision) ] \n\$ " | |
;; | |
esac | |
################################################################# | |
# keep a permanent history of commands typed across all windows. | |
# This uses the history command to match the part that was typed, | |
# then uses BASH_REMATCH to extract that part and store it in the | |
# .persistent_history file. This is run automatically every time | |
# the prompt is redisplayed. | |
log_bash_persistent_history() { | |
[[ | |
$(history 1) =~ ^[[:space:]]*[0-9]+[[:space:]]+(.*)$ | |
]] | |
date_part=$(date "+%Y-%m-%dT%H:%M:%S") | |
command_part="${BASH_REMATCH[1]}" | |
if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ]; then | |
echo $date_part "|" "$command_part" >> ~/.persistent_history | |
export PERSISTENT_HISTORY_LAST="$command_part" | |
fi | |
} | |
# Stuff to do on PROMPT_COMMAND | |
# persistent history and set the title of the window to the current directory | |
run_on_prompt_command() { | |
log_bash_persistent_history | |
echo -ne "\033]0;${PWD##*/}\007" | |
} | |
PROMPT_COMMAND="run_on_prompt_command" | |
# gets the last 10 matching unique commands from history, sorted by recency | |
phistory() { | |
grep $@ ~/.persistent_history | sort -k 2 |uniq -f 2 |sort |head -10 | |
} | |
####################### | |
# some find helpers | |
findinsource() { | |
find . \( -iname "*.py" -or -iname "*.[ch]" -or -iname "*.cpp" -or -iname "*.js" -or -iname "*.cs" \) -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 finder helpers | |
# cd to the path of the front Finder window | |
cdf() { | |
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` | |
echo $target | |
if [ "$target" != "" ]; then | |
cd "$target" | |
else | |
echo 'No Finder window found' >&2 | |
fi | |
} | |
# open finder at the directory specified -- no args means current directory | |
f() { | |
if [ "$1" != "" ]; then | |
open -a Finder $1 | |
else | |
open -a Finder ./ | |
fi | |
} | |
######################## | |
# 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 | |
} | |
gitlog() { | |
git log --max-count 20 --pretty=oneline --abbrev-commit --decorate $@ | |
} | |
gitlog1() { | |
git log --max-count 1 --pretty=oneline --abbrev-commit --no-merges --decorate $@ | |
} | |
######################## | |
# 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 | |
} | |
## just for fun, ccalc trims the newline | |
## and copies the result directly to the clipboard | |
function ccalc () { | |
calc $@|tr -d '\n'|pbcopy | |
} | |
function resync_master() | |
{ | |
git stash save | |
git checkout master | |
git fetch --prune --tags | |
git pull origin master | |
git stash pop | |
} | |
######################## | |
# 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 | |
} | |
## open a man file in sublime text | |
function sman() | |
{ | |
man $@ | col -b | open -f -a /Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text; | |
} | |
######################### | |
# curl help that's faster than trying to read through man curl. | |
function curlexamples() { | |
echo curl --include --get '"http://localhost:8081/key"' | |
echo curl --include -XPUT '"http://localhost:8081/key"' -H '"Content-Type:application/json"' -d "'{\"msg\":\"hello, world\"}'" | |
} | |
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment