Skip to content

Instantly share code, notes, and snippets.

@garretttaco
Last active April 15, 2017 00:08
Show Gist options
  • Save garretttaco/b9be5ca033fd0b9e7c8b to your computer and use it in GitHub Desktop.
Save garretttaco/b9be5ca033fd0b9e7c8b to your computer and use it in GitHub Desktop.
This is my ever improving bash_profile/bashrc file that I use on my computers.
#Add vim to command line
set -o vi
# Random
alias ll='ls -la'
alias apache='sudo apachectl restart'
alias hosts='sudo vi /etc/hosts'
alias mysqlstart='sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist'
alias mysqlstop='sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist'
alias eip='curl icanhazip.com'
alias iip='ifconfig | grep 192'
alias mysql_stop='sudo /usr/local/mysql/support-files/mysql.server stop'
alias mysql_start='sudo /usr/local/mysql/support-files/mysql.server start'
alias vhosts='sudo vi /etc/apache2/extra/httpd-vhosts.conf'
alias 300='npm run build-development'
alias 300Prod='npm run build-production'
alias 300Old='babel src/ --out-dir out/ --presets react,es2015 -w'
alias bs='source ~/.bash_profile'
alias bp='subl ~/.bash_profile'
alias myip='ifconfig | grep 192'
alias gaa='git add -A; git commit --amend --no-edit'
alias amend='git commit --amend'
export PATH="/usr/local/mysql/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="~/.nodenv/shims:$PATH"
export PATH="/usr/local/share/npm/bin:$PATH"
alias lock='/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend'
alias ngrok='~/Sites/ngrok'
# Not installed via npm, so keep this commented out unless switching from npm because of nodenv
export PATH="$HOME/.yarn/bin:$PATH"
# GIT
alias gdiff='git diff-index --name-only HEAD'
alias gcp='git checkout -'
alias gco='git checkout'
alias ga='git add -A'
alias gs='git status'
alias gl='git log --stat'
alias gb='git branch'
alias gbd='git branch -d'
alias gbrm='git push origin'
alias grh='git reset --hard'
alias gr='git reflog'
alias gaa='git commit -am --amend'
alias gp='git pull'
alias push='git push'
alias staged='git diff --cached --name-only'
alias unadd='git reset .'
alias uncommit='git reset HEAD^'
source ~/git-completion.bash
source ~/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
export PS1='\w$(__git_ps1 " [%s] ")\$ '
__git_complete gco _git_checkout
__git_complete gbrm _git_checkout
__git_complete gbd _git_checkout
# Commit with the appropriate issue number, if available in the branch, otherwise, the normal message is used
commit() {
branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
IFS='-' read -r issueNumber string <<< "$branch"
if [[ "$issueNumber" =~ ^[0-9]+$ ]]
then
msg="#$issueNumber $1"
else
msg="$1"
fi
echo committing $msg
git commit -am "$msg"
}
alias gc='commit'
# Create branch and switch to it
gbco() {
gb $1
gco $1
}
pushNew() {
branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
git push --set-upstream origin $branch
}
checkPort() {
sudo lsof -i :"$1"
}
# From https://zarino.co.uk/post/git-set-upstream/
setUpstream() {
!git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`
}
# npm -> yarn
################### DOCKER
#export DOCKER_TLS_VERIFY="1"
#export DOCKER_HOST="tcp://192.168.99.100:2376"
#export DOCKER_CERT_PATH="/Users/Garrett/.docker/machine/machines/default"
# export DOCKER_MACHINE_NAME="default"
dls() {
docker ps
}
dll() {
docker ps -a
}
dim() {
docker images
}
# docker stop
dsto() {
if [[ $# -eq 0 ]]
then
echo "Which container? Provide 1 argument."
return 0
fi
docker stop $1
}
# docker start
dsta() {
if [[ $# -eq 0 ]]
then
echo "Which container? Provide 1 argument."
return 0
fi
docker start $1
}
# docker remove
drm() {
if [[ $# -eq 0 ]]
then
echo "Which container? Provide 1 argument."
return 0
fi
docker rm $1
}
# docker stop all running
dsar() {
if [[ $# -eq 0 ]]
then
docker ps | tail -n +2 |cut -d ' ' -f 1 | xargs docker stop
else
dsto $1;
fi
}
alias dstop='dsar'
# docker remove all stopped
dras() {
docker ps -a | tail -n +2 | grep Exited | cut -d ' ' -f 1 | xargs docker rm
}
# docker kill all
docker-killall() {
dsar
dras
}
alias dka='docker-killall'
# Docker get an ext ip
dip() {
if [[ $# -eq 0 ]]
then
echo "Which container? Provide 1 argument."
return 0
fi
docker inspect --format='{{.NetworkSettings.IPAddress}}' $1
}
drun() {
if [[ $# -eq 0 ]]
then
echo "Which container? Provide 1 argument."
return 0
fi
case "$1" in
'web' )
docker run -d \
--name web \
-p 80:80 \
-e APP=web \
--link db:db \
-v /Users/Garrett/NetBeansProjects:/var/www/mount \
-t devbox \
apache2-foreground
;;
'phantom' )
docker run -d \
--name phantom \
-p 81:81 \
-e APP=phantom \
-v /Users/Garrett/NetBeansProjects:/var/www/html \
-t devbox \
apache2-foreground
;;
'db' )
docker run -d \
--name db \
-e APP=db \
-e MYSQL_ROOT_PASSWORD=rootpwd \
percona
;;
'java' )
docker run -d \
--name java \
-p 80:80 \
-e APP=java \
# -v /Users/Garrett/NetBeansProjects:/var/www/mount \
-t devbox \
buildpack-deps:jessie-curl
;;
esac
}
docker-enter() {
if [[ $# -eq 0 ]]
then
echo "Which container? Provide 1 argument."
return 0
fi
docker exec -ti $1 bash
}
alias de='docker-enter'
################### GIT
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
# commit() {
# git add -A
# git pull
# git commit -m $1
# }
syncGHKey() {
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/bg_github
#ssh-add -l
}
alias key='syncGHKey'
# Add the key on load of each individual terminal window
key
################### OTHER
listening() {
# See whats listening to a port lsof -i tcp:{port#}
sudo lsof -i -n -P | grep TCP
}
port() {
lsof -i -n -P | grep "$1"
}
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
#
if type complete &>/dev/null; then
_npm_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
fi
local si="$IFS"
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
complete -o default -F _npm_completion npm
elif type compdef &>/dev/null; then
_npm_completion() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
compdef _npm_completion npm
elif type compctl &>/dev/null; then
_npm_completion () {
local cword line point words si
read -Ac words
read -cn cword
let cword-=1
read -l line
read -ln point
si="$IFS"
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
COMP_LINE="$line" \
COMP_POINT="$point" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
compctl -K _npm_completion npm
fi
###-end-npm-completion-###
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/Garrett/google-cloud-sdk/path.bash.inc' ]; then source '/Users/Garrett/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/Garrett/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/Garrett/google-cloud-sdk/completion.bash.inc'; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment