Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
140 lines (123 sloc) 3.71 KB
# PATHS
export PATH="$PATH:$HOME/terraform"
export PATH="$PATH:$HOME/packer"
export GOPATH="$HOME/dev/go"
export PATH="$PATH:$GOPATH/bin"
export PATH="$PATH:$HOME/Library/Android/sdk/platform-tools"
# ALIASES
alias awsc='env | grep "AWS"'
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
alias ubuntu="sh -c 'cd $HOME/ubuntu && vagrant up && vagrant ssh'"
alias dev="cd ~/dev"
alias dockercraft='docker run -t -i -d -p 25565:25565 -v /var/run/docker.sock:/var/run/docker.sock --name dockercraft gaetan/dockercraft'
alias goctm='cd $GOPATH/src/github.com/ComparetheMarket'
alias gbi='go build && go install'
# RVM
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# CHEF
eval "$(chef shell-init bash)"
# FUNCTIONS
# set docker environment
function dkr {
if [ -n "$1" ]; then
docker-machine start "$1"
eval $(docker-machine env "$1" | grep -Eo 'eval.*')
fi
}
# awsp - AWS credential profile changer
function awsp {
profile=$(echo "$1" | tr [:upper:] [:lower:])
if [ "$profile" == "unset" ]; then
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
return 0
fi
data=$(awk "/\[$1\]/{y=1;next}y" ~/.aws/credentials | head -2 | sed 's/^.*= //')
if [ -z "$data" ]; then
echo "AWS profile for '$1' does not exist"
return 1
fi
export AWS_ACCESS_KEY_ID=$(echo "$data" | sed -n 1p | xargs)
export AWS_SECRET_ACCESS_KEY=$(echo "$data" | sed -n 2p | xargs)
}
complete -W "$(cat $HOME/.aws/credentials | grep -Eo '\[.*\]' | tr -d '[]')${IFS}unset" awsp
# sshi & scpi - secure SSH (ssh -i) and secure copy (scp -i) shortcuts
export KEY_DIR="$HOME/security/pem-keys/"
_keys() {
keys=$(find -x "${KEY_DIR}" -type f -name "*.pem" -print0 | xargs -0 -n1 basename)
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case $COMP_CWORD in
1)
COMPREPLY=( $(compgen -W "${keys}" -- ${cur}) )
;;
*)
COMPREPLY=( $(compgen -o default -- ${cur}) )
;;
esac
return 0
}
function sshi {
if [ $# -lt 2 ]; then
echo "Usage: sshi [key.pem] [user@host]"
return
fi
ssh -i "${KEY_DIR}${1}" "$2"
}
complete -o nospace -F _keys sshi
function scpi {
if [ $# -lt 3 ]; then
echo "Usage: scpi [key.pem] [source] [destination]"
return
fi
set -f
scpcommand="scp -r -i ${KEY_DIR}${1} $2 $3"
set +f
$scpcommand
}
complete -o nospace -F _keys scpi
# bashbk - backup .bash_profile to github
function bashbk {
curdir=$PWD
cd "$HOME/dev/bash_profile/"
cp "$HOME/.bash_profile" .
git add .bash_profile
git commit -m "$(date): Backup of .bash_profile"
git pull --rebase
git push
cd "$curdir"
}
# desource - substitute source statements in file with contents from sourced file
function desource {
if [ ! -f "$1" ]; then
echo "Invalid file: $1"
return
fi
declare tmp
while read -r line; do
if [ "${line:0:1}" == '#' ]; then continue; fi
file=$(echo "$line" | perl -nle 'print $1 if m{(?>source )(.+)}' | sed 's|"||g')
if [ -n "$file" ]; then
case "${file:0:1}" in
'/') ;;
'~') ;;
'$') ;;
*) file="$(cd `dirname $1` && pwd)/$file"
esac
file=$(echo "$file" | sed "s|~|$HOME|" | sed "s|\$HOME|$HOME|")
file="$(cd `dirname $file` && pwd)/$(basename $file)"
if [ -f "$file" ]; then
tmp="$tmp\n$(cat $file)"
else
echo "Invalid file: $file"
return
fi
else
tmp="$tmp\n$line"
fi
done < "$1"
echo -e "$tmp"
}