Last active
October 4, 2016 23:39
-
-
Save mycargus/688b5df5fc50a5076cd4 to your computer and use it in GitHub Desktop.
My mac bash setup
This file contains 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
[[ -s ~/.bashrc ]] && source ~/.bashrc # load .bashrc | |
[[ -s ~/.bash_profile_instructure ]] && source ~/.bash_profile_instructure # load .bash_profile_instructure |
This file contains 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
###################### | |
### CUSTOMIZE PATH ### | |
###################### | |
case ":$PATH:" in | |
*:$HOME/bin:*) ;; # do nothing if $PATH already contains $HOME/bin | |
*) PATH=$HOME/bin:$PATH ;; # in every other case, add it to the front | |
esac | |
case ":$PATH:" in | |
*:/usr/local/bin:*) ;; # do nothing if $PATH already contains /usr/local/bin | |
*) PATH=/usr/local/bin:$PATH ;; # in every other case, add it to the front | |
esac | |
case ":$PATH:" in | |
*:/usr/local/sbin:*) ;; # do nothing if $PATH already contains /usr/local/sbin | |
*) PATH=/usr/local/sbin:$PATH ;; # in every other case, add it to the front | |
esac | |
case ":$PATH:" in | |
*:$HOME/.nvm:*) ;; # do nothing if $PATH already contains $HOME/.nvm | |
*) PATH=$HOME/.nvm:$PATH ;; # in every other case, add it to the front | |
esac | |
case ":$PATH:" in | |
*:usr/local/opt/go/libexec/bin:*) ;; # do nothing if $PATH already contains usr/local/opt/go/libexec/bin | |
*) PATH=usr/local/opt/go/libexec/bin:$PATH ;; # in every other case, add it to the front | |
esac | |
export NVM_DIR=~/.nvm | |
source $(brew --prefix nvm)/nvm.sh | |
# Add the brew bin to $PATH | |
if $(which brew >/dev/null 2>&1); then | |
export PATH="$PATH:$(brew --prefix)/bin" | |
fi | |
# Add the autojump tool | |
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh | |
###################### | |
## CUSTOMIZE PROMPT ## | |
###################### | |
function prompt { # from http://dobsondev.com/customizing-your-terminal/ | |
local BLACK="\[\033[0;30m\]" | |
local BLACKBOLD="\[\033[1;30m\]" | |
local RED="\[\033[0;31m\]" | |
local REDBOLD="\[\033[1;31m\]" | |
local GREEN="\[\033[0;32m\]" | |
local GREENBOLD="\[\033[1;32m\]" | |
local YELLOW="\[\033[0;33m\]" | |
local YELLOWBOLD="\[\033[1;33m\]" | |
local BLUE="\[\033[0;34m\]" | |
local BLUEBOLD="\[\033[1;34m\]" | |
local PURPLE="\[\033[0;35m\]" | |
local PURPLEBOLD="\[\033[1;35m\]" | |
local CYAN="\[\033[0;36m\]" | |
local CYANBOLD="\[\033[1;36m\]" | |
local WHITE="\[\033[0;37m\]" | |
local WHITEBOLD="\[\033[1;37m\]" | |
local RESETCOLOR="\[\e[00m\]" | |
export GITAWAREPROMPT=~/.bash/git-aware-prompt | |
source $GITAWAREPROMPT/main.sh | |
#export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " | |
export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ " | |
export GIT_PS1_SHOWDIRTYSTATE=1 # Show dirty state in prompt when in Git repos | |
export PS1="\n$RED\u $PURPLE@ $GREEN\W \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\] \n $BLUE[\#] \$ $RESETCOLOR" | |
export PS2="| → $RESETCOLOR" | |
} | |
prompt | |
# set terminal tab title | |
function title { | |
if [ "$1" ] | |
then | |
unset PROMPT_COMMAND | |
echo -ne "\033]0;${*}\007" | |
else | |
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"' | |
fi | |
} | |
###################### | |
##### BASH TOOLS ##### | |
###################### | |
# bash-completion | |
if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
. $(brew --prefix)/etc/bash_completion | |
fi | |
# rbenv | |
export RBENV_ROOT=/usr/local/var/rbenv # use Homebrew's directories rather than ~/.rbenv | |
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi # enable shims and autocompletion | |
# nvm | |
export NVM_DIR=~/.nvm | |
source $(brew --prefix nvm)/nvm.sh | |
# git-flow-completion for bash | |
source ~/bin/git-flow-completion.bash | |
# edit .bashrc file in vim, then reload source bash upon wq | |
alias bashrc='vim ~/.bashrc && source ~/.bashrc' | |
# refresh shell | |
alias reload='source ~/.bash_profile && rbenv rehash' | |
# list all alia.ses in ~/.bashrc (symbolic link) | |
alias la='grep -R "alias" ~/.bashrc | cut -c 30-' | |
###################### | |
### MISC FUNCTIONS ### | |
###################### | |
# gracefully kill processes by name | |
stop() { | |
for process in "$@"; do | |
if ps aux | grep $process | grep -v grep > /dev/null; then | |
printf "\nKilling $process softly:\n" | |
pkill -fl $process | |
printf "... It's dead now.\n" | |
else | |
printf "\n$process isn't running. Skipping ...\n" | |
fi | |
done | |
} | |
# get my network's wifi password # TODO | |
whats_wifi_password() { | |
printf 'Not Implemented' | |
# security find-generic-password -ga $1 | ag password | |
} | |
###################### | |
##### NETWORKING ##### | |
###################### | |
alias ports='netstat -tulanp' | |
# simple ip | |
alias ip='ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -f2' | |
# more details | |
alias ip1="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'" | |
# external ip | |
alias my_public_ip="curl -s http://www.showmyip.gr | grep 'IP is:' | cut -c 21-" | |
# Stop after sending count ECHO_REQUEST packets | |
alias ping='ping -c 5' | |
# Do not wait interval 1 second, go fast! | |
alias fastping='ping -c 100 -s.2' | |
# resume wget by default | |
alias wget='wget -c' | |
###################### | |
### FILE MANAGEMENT ## | |
###################### | |
alias lh='ls -lhaG' | |
alias ls='ls -aG' | |
# show progress bar on an ongoing file copy | |
alias progress='rsync --progress -ravz' | |
# Show text file without comment lines, e.g. $ catnocomment /etc/squid.conf | |
alias catnocomment='grep -Ev '\''^(#|$)'\''' | |
# confirm significant actions | |
alias rm='rm -i' | |
alias mv='mv -i' | |
alias cp='cp -i' | |
alias ln='ln -i' | |
alias root='sudo -i' | |
alias su='sudo -i' | |
alias reboot='root /sbin/reboot' | |
alias shutdown='root /sbin/shutdown' | |
# display contents of pwd after `cd` | |
cdl() { | |
cd "$1" | |
ls | |
} | |
# make dir (and any parent dirs), then cd into it | |
mkdirp() { | |
mkdir -pv "$1" | |
cd "$1" | |
} | |
# delete dir (and any child dirs and their contents) | |
rmdirp() { | |
rm -rf "$1" | |
} | |
# `up 4` goes up 4 directories | |
up() { | |
local path i | |
for (( i=0; i < $1; i++ )); do | |
path+=../ | |
done | |
cd "$path" | |
} | |
# extract all the things!!! | |
extract() { | |
if [ -z "$1" ]; then | |
# display usage if no parameters given | |
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>" | |
else | |
if [ -f $1 ]; then | |
# NAME=${1%.*} | |
# mkdir $NAME && cd $NAME | |
case $1 in | |
*.tar.bz2) tar xvjf ../$1 ;; | |
*.tar.gz) tar xvzf ../$1 ;; | |
*.tar.xz) tar xvJf ../$1 ;; | |
*.lzma) unlzma ../$1 ;; | |
*.bz2) bunzip2 ../$1 ;; | |
*.rar) unrar x -ad ../$1 ;; | |
*.gz) gunzip ../$1 ;; | |
*.tar) tar xvf ../$1 ;; | |
*.tbz2) tar xvjf ../$1 ;; | |
*.tgz) tar xvzf ../$1 ;; | |
*.zip) unzip ../$1 ;; | |
*.Z) uncompress ../$1 ;; | |
*.7z) 7z x ../$1 ;; | |
*.xz) unxz ../$1 ;; | |
*.exe) cabextract ../$1 ;; | |
*) echo "extract: '$1' - unknown archive method" ;; | |
esac | |
else | |
echo "$1 - file does not exist" | |
fi | |
fi | |
} | |
# print pretty JSON | |
json_pretty() { | |
cat $1 | underscore print --color | |
} | |
###################### | |
####### RAILS ######## | |
###################### | |
alias binstall='bundle install' | |
alias bupdate='bundle update' | |
alias bexec='bundle exec' | |
alias bake='bexec rake' | |
alias dev='RAILS_ENV=development' | |
alias test='RAILS_ENV=test' | |
alias prod='RAILS_ENV=production' | |
alias drake='dev bake' | |
alias trake='test bake' | |
# Instructure environment | |
alias cd_canvas_local='cd ~/code/canvas-lms-local/' | |
alias compile_assets='bake canvas:compile_assets[0,0,1,1]' # don't generate docs, don't check i18n syntax, do compile css, do compile js | |
alias compile_js='bake js:generate' | |
alias dev_console='dev bexec script/console' | |
alias dev_server='dev bexec script/server' | |
alias reset_db_dev='dropdb canvas_development && createdb canvas_development && drake db:migrate && drake db:load_initial_data' | |
alias reset_db_test='dropdb canvas_test && createdb canvas_test && trake db:migrate && trake db:load_initial_data' | |
alias start_delayed_jobs='cd_canvas_local && script/delayed_job start' | |
alias run_delayed_jobs='cd_canvas_local && script/delayed_job run' | |
alias start_postgres='title postgres && postgres -D /var/lib/postgres/data' | |
alias start_selenium='title selenium && java -jar ~/code/selenium-server-standalone-2.48.2.jar' | |
alias start_guard='title guard && bexec guard' | |
alias stop_testing='stop postgres selenium guard gulp delayed_job' | |
create_new_specs_branch() { | |
cd_canvas_local | |
printf "\nI moved you into $(pwd). You're welcome.\n" | |
printf "\nStashing any changes ... " | |
git stash | |
prepare | |
printf "\nCreating new branch: $(echo $1)\n" | |
git c -b $1 | |
echo " Setting branch upstream to master ... " | |
git link-to-master | |
printf "\nDon't forget to 'git stash pop' if I stashed changes for you.\n" | |
printf "\n\"Yesterday, you said tomorrow. JUST DO IT!!!\" -- Shia LaBeouf\n" | |
} | |
ssh_into_portal() { | |
printf "\nOpening ssh connection using ~/portal.pem ... " | |
ssh -i ~/portal.pem $1 | |
} | |
# DOCKER | |
alias totes='docker-compose run --rm web' | |
# Purpose: Remove all non-running images and containers | |
# Use `docker-cleanup --dry-run` to see what would be deleted. | |
function docker-cleanup { | |
EXITED=$(docker ps -q -f status=exited) | |
DANGLING=$(docker images -q -f "dangling=true") | |
if [ "$1" == "--dry-run" ]; then | |
echo "==> Would stop containers:" | |
echo $EXITED | |
echo "==> And images:" | |
echo $DANGLING | |
else | |
if [ -n "$EXITED" ]; then | |
docker rm $EXITED | |
else | |
echo "No containers to remove." | |
fi | |
if [ -n "$DANGLING" ]; then | |
docker rmi $DANGLING | |
else | |
echo "No images to remove." | |
fi | |
fi | |
} | |
###################### | |
######## APPS ######## | |
###################### | |
alias subl='~/bin/subl' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment