Skip to content

Instantly share code, notes, and snippets.

@dannyroberts
Last active February 7, 2020 18:08
Show Gist options
  • Save dannyroberts/5165174 to your computer and use it in GitHub Desktop.
Save dannyroberts/5165174 to your computer and use it in GitHub Desktop.
requires other stuff to be installed (obviously git)

Install

cd ~
git clone https://gist.github.com/5165174.git bash
ln -s bash/bash_profile .bash_profile
# export PS1='\[\e[1;34m\]\d \t\[\e[m\] \h:\W \u\$ '
alias person=man
alias dimagi-gpg="gpg --keyring dimagi.gpg --no-default-keyring"
alias bp="mate ~/.bash_profile"
alias rl="source ~/.bash_profile"
alias icds="sudo openconnect --no-dtls -c /Users/droberts/Downloads/umesh.crt -k /Users/droberts/Downloads/umesh.key sconnect.nic.in --script=/usr/local/etc/vpnc-script"
GRADLE_HOME="/opt/gradle-2.11/lib"
PATH=/opt/local/bin:/usr/local/bin:$PATH:/opt/lessc/bin:/usr/local/sbin
export REUSE_DB=1
function delete-pyc() {
find . -name '*.pyc' -delete
}
function pull-latest-master() {
git checkout master; git pull &
git submodule foreach --recursive 'git checkout master; git pull origin master &'
until [ -z "$(ps aux | grep '[g]it pull')" ]; do sleep 1; done
}
function update-code() {
pull-latest-master
delete-pyc
}
rs='.internal.commcarehq.org'
alias branch="git branch | grep '^\*' | sed 's/* //'"
alias pho='git push origin $(branch)'
function delete-merged() {
if [ $(branch) = 'master' ]
then git branch --merged master | grep -v '\*' | xargs -n1 git branch -d
else echo "You are not on branch master"
fi
}
function delete-merged-remote() {
git fetch
git remote prune origin
git branch --remote --merged master | grep -v 'master$' | sed s:origin/:: | xargs -I% git push origin :%
}
function es-list() {
curl -s 'http://localhost:9200/_status' | jsawk 'return Object.keys(this.indices).join("\n")'
}
function es-alias() {
curl -XPOST 'http://localhost:9200/_aliases' -d \
'{ "actions": [ {"add": {"index": "'"$1"'_'"$2"'", "alias": "'$1'"}}]}'
}
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
##
# Your previous /Users/droberts/.bash_profile file was backed up as /Users/droberts/.bash_profile.macports-saved_2012-12-25_at_17:24:28
##
# MacPorts Installer addition on 2012-12-25_at_17:24:28: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
##
# Your previous /Users/droberts/.bash_profile file was backed up as /Users/droberts/.bash_profile.macports-saved_2012-12-25_at_20:35:15
##
# MacPorts Installer addition on 2012-12-25_at_20:35:15: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
source ~/bash/z.sh
source ~/bash/git-aliases.sh
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/local/bin/python3'
source virtualenvwrapper.sh
source ~/bash/misc-shortcuts.sh
source ~/bash/commcare-shortcuts.sh
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
# added by gpg-scripts on Fri Aug 19 10:37:54 EDT 2016
export PATH=$PATH:/Users/droberts/gpg-scripts
GPG_TTY=`tty`
export GPG_TTY
# commcare-cloud
# export COMMCARE_CLOUD_ENVIRONMENTS=/Users/droberts/dimagi/commcare-cloud/environments
# export ANSIBLE_ROLES_PATH=~/.ansible/roles
# export PATH=$PATH:~/.commcare-cloud/bin
# source ~/.commcare-cloud/repo/src/commcare_cloud/.bash_completion
export ANSIBLE_NOCOWS=1
source ~/.commcare-cloud/load_config.sh
export COMMCARE_CLOUD_DEFAULT_USERNAME=droberts
eval "$(rbenv init -)"
function makeccz() {
source_dir=$1
current_dir=`pwd`
cd $source_dir && zip -r $current_dir/commcare.ccz . && cd $current_dir
}
alias commcare="java -jar /Users/droberts/dimagi/commcare-cli/commcare-cli.jar"
function commcare-cli-update() {
curl https://jenkins.dimagi.com/job/commcare-mobile/lastSuccessfulBuild/artifact/build/libs/commcare-cli.jar > /Users/droberts/dimagi/commcare-cli/commcare-cli.jar
}
alias djtest='REUSE_DB=1 ./manage.py test --nocapture --nologcapture --noinput'
function runserver-then() {
script -q /dev/null ./manage.py runserver | {
while read line
do
if echo "$line" | grep 'Starting development server at'
then
"$@"
else
echo "$line"
fi
done
}
}
source /usr/local/git/contrib/completion/git-completion.bash
alias g="git"; __git_complete g _git
alias l="git status"
alias d="git diff"; __git_complete d _git_diff
alias ds="git diff --cached"
alias a="git add "
function m() {
message="$(echo "$1" | python3 -c 'import sys; string = sys.stdin.read(); print(string[:1].upper() + string[1:])')"
git commit -m "$message"
}
function o() {
if [ $1 == '-b' ]
then
shift
branch_name=$1
shift
git checkout -b dmr/${branch_name} "$@"
else
git checkout "$@"
fi
}
__git_complete o _git_checkout
alias om="git checkout master"
alias ph="git push"
alias pl="git pull"
alias rh="git reset HEAD"
alias mg="git merge"; __git_complete mg _git_merge
alias gl="git log"; __git_complete gl _git_log
alias gs="git stash"
alias gsa="git stash apply"
alias b="git branch"; __git_complete b _git_branch
function delete-pyc() {
find . -name '*.pyc' -delete
}
function pull-latest-master() {
git checkout master; git pull
git submodule update --init
git submodule foreach --recursive 'if [[ $(pwd) != *"corehq/apps"* ]]; then git checkout master; git pull & fi'
until [ -z "$(ps aux | grep '[g]it pull')" ]; do sleep 1; done
delete-merged
# this is just copy-pasted from delete-merged
git submodule foreach --recursive "if [[ $(pwd) != *"corehq/apps"* ]]; then git branch --merged master | grep -v '\*' | xargs -n1 git branch -d; fi"
}
function update-code() {
pull-latest-master
delete-pyc
}
function switch-submodule-branches() {
git submodule foreach "git branch | grep $1 && git checkout $1 || exit 0"
}
alias branch="git branch | grep '^\*' | sed 's/* //'"
function pho() {
b=$(branch)
git push origin $b "$@"
git rev-parse --abbrev-ref $b @{upstream} &> /dev/null || git branch --set-upstream-to=origin/$b
}
function force-edit-url {
git remote set-url origin $(pho 2>&1 | grep Use | awk '{print $2}')
}
function delete-merged() {
if [ $(branch) = 'master' ]
then git branch --merged master | grep -v '\*' | xargs -n1 git branch -d
else echo "You are not on branch master"
fi
}
function delete-merged-remote() {
git fetch
git remote prune origin
git branch --remote --merged master | grep -v 'master$' | grep 'origin/' | sed s:origin/:: | xargs -I% git push origin :%
}
# o that's bad
function submodule-branches() {
git submodule foreach 'echo $(basename `pwd`) " " `git branch | grep "^\*" | sed "s/* //"`' | grep -v Entering | grep -v master | awk '{ printf("%s\t%s\n", $1, $2) }'
}
function lba() {
for branch in $(b | grep -v '^\*')
do
git log -n1 --pretty="%ci $branch (%an)" $branch
done | sort --reverse
}
function lb() {
lba | head -n 20
}
alias checkmark="echo ✓"
alias xmark="echo ✗"
function pprintjson() {
python -m json.tool
}
alias pbj="pbpaste | pprintjson"
alias new-password="head -c 18 /dev/urandom | base64"
alias pg="postgres -D /usr/local/var/postgres"
function resetkext() {
kextstat | grep -v com.apple | grep tun | sed -E 's/ +/ /g' | cut -d' ' -f 7 | xargs -n1 sudo kextunload -b
}
# Copyright (c) 2009 rupa deadwyler under the WTFPL license
# maintains a jump-list of the directories you actually use
#
# INSTALL:
# * put something like this in your .bashrc/.zshrc:
# . /path/to/z.sh
# * cd around for a while to build up the db
# * PROFIT!!
# * optionally:
# set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).
# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
#
# USE:
# * z foo # cd to most frecent dir matching foo
# * z foo bar # cd to most frecent dir matching foo and bar
# * z -r foo # cd to highest ranked dir matching foo
# * z -t foo # cd to most recently accessed dir matching foo
# * z -l foo # list matches instead of cd
# * z -c foo # restrict matches to subdirs of $PWD
case $- in
*i*) ;;
*) echo 'ERROR: z.sh is meant to be sourced, not directly executed.'
esac
_z() {
local datafile="${_Z_DATA:-$HOME/.z}"
# bail out if we don't own ~/.z (we're another user but our ENV is still set)
[ -f "$datafile" -a ! -O "$datafile" ] && return
# add entries
if [ "$1" = "--add" ]; then
shift
# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return
# don't track excluded dirs
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
[ "$*" = "$exclude" ] && return
done
# maintain the file
local tempfile
tempfile="$(mktemp $datafile.XXXXXX)" || return
while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '
BEGIN {
rank[path] = 1
time[path] = now
}
$2 >= 1 {
if( $1 == path ) {
rank[$1] = $2 + 1
time[$1] = now
} else {
rank[$1] = $2
time[$1] = $3
}
count += $2
}
END {
if( count > 6000 ) {
for( i in rank ) print i "|" 0.99*rank[i] "|" time[i] # aging
} else for( i in rank ) print i "|" rank[i] "|" time[i]
}
' 2>/dev/null >| "$tempfile"
if [ $? -ne 0 -a -f "$datafile" ]; then
env rm -f "$tempfile"
else
env mv -f "$tempfile" "$datafile"
fi
# tab completion
elif [ "$1" = "--complete" ]; then
while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v q="$2" -F"|" '
BEGIN {
if( q == tolower(q) ) nocase = 1
split(substr(q,3),fnd," ")
}
{
if( nocase ) {
for( i in fnd ) tolower($1) !~ tolower(fnd[i]) && $1 = ""
} else {
for( i in fnd ) $1 !~ fnd[i] && $1 = ""
}
if( $1 ) print $1
}
' 2>/dev/null
else
# list/go
while [ "$1" ]; do case "$1" in
--) while [ "$1" ]; do shift; local fnd="$fnd $1";done;;
-*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in
c) local fnd="^$PWD $fnd";;
h) echo "${_Z_CMD:-z} [-chlrt] args" >&2; return;;
l) local list=1;;
r) local typ="rank";;
t) local typ="recent";;
esac; opt=${opt:1}; done;;
*) local fnd="$fnd $1";;
esac; local last=$1; shift; done
[ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1
# if we hit enter on a completion just go there
case "$last" in
# completions will always start with /
/*) [ -z "$list" -a -d "$last" ] && cd "$last" && return;;
esac
# no file yet
[ -f "$datafile" ] || return
local cd
cd="$(while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" '
function frecent(rank, time) {
dx = t-time
if( dx < 3600 ) return rank*4
if( dx < 86400 ) return rank*2
if( dx < 604800 ) return rank/2
return rank/4
}
function output(files, toopen, override) {
if( list ) {
cmd = "sort -n >&2"
for( i in files ) if( files[i] ) printf "%-10s %s\n", files[i], i | cmd
if( override ) printf "%-10s %s\n", "common:", override > "/dev/stderr"
} else {
if( override ) toopen = override
print toopen
}
}
function common(matches) {
# shortest match
for( i in matches ) {
if( matches[i] && (!short || length(i) < length(short)) ) short = i
}
if( short == "/" ) return
# shortest match must be common to each match. escape special characters in
# a copy when testing, so we can return the original.
clean_short = short
gsub(/[\(\)\[\]\|]/, "\\\\&", clean_short)
for( i in matches ) if( matches[i] && i !~ clean_short ) return
return short
}
BEGIN { split(q, a, " "); oldf = noldf = -9999999999 }
{
if( typ == "rank" ) {
f = $2
} else if( typ == "recent" ) {
f = $3-t
} else f = frecent($2, $3)
wcase[$1] = nocase[$1] = f
for( i in a ) {
if( $1 !~ a[i] ) delete wcase[$1]
if( tolower($1) !~ tolower(a[i]) ) delete nocase[$1]
}
if( wcase[$1] && wcase[$1] > oldf ) {
cx = $1
oldf = wcase[$1]
} else if( nocase[$1] && nocase[$1] > noldf ) {
ncx = $1
noldf = nocase[$1]
}
}
END {
if( cx ) {
output(wcase, cx, common(wcase))
} else if( ncx ) output(nocase, ncx, common(nocase))
}
')"
[ $? -gt 0 ] && return
[ "$cd" ] && cd "$cd"
fi
}
alias ${_Z_CMD:-z}='_z 2>&1'
[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P"
if compctl &> /dev/null; then
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# zsh populate directory list, avoid clobbering any other precmds
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
_z --add "${PWD:a}"
}
else
_z_precmd() {
_z --add "${PWD:A}"
}
fi
precmd_functions+=(_z_precmd)
}
# zsh tab completion
_z_zsh_tab_completion() {
local compl
read -l compl
reply=(${(f)"$(_z --complete "$compl")"})
}
compctl -U -K _z_zsh_tab_completion _z
elif complete &> /dev/null; then
# bash tab completion
complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z}
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# bash populate directory list. avoid clobbering other PROMPT_COMMANDs.
echo $PROMPT_COMMAND | grep -q "_z --add" || {
PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND"
}
}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment