Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
370 lines (297 sloc) 11.2 KB
### For .bash_profile
# if [ -f ~/.bashrc ] ; then
# . ~/.bashrc
# fi
######
# .bashrc
if [[ $OSTYPE == darwin* ]] ; then
PATH=$PATH:$HOME/.gem/ruby/1.8/bin
export PATH
export EDITOR=vi
export SVN_EDITOR=vi
export GEMEDITOR='subl -w'
export VISUAL='subl -w'
export COPYFILE_DISABLE=true
## Terminal
if [ -f $HOME/.special_characters ]; then
source $HOME/.special_characters
else
function spchar {
echo "$"
}
fi
export PS1='\[\e[0;44;93m\]\W\[\e[0m\] \[\e[1;35m\]`date +'%H:%M'` \[\e[1;31m\]`spchar` \[\e[0m\]'
# export PS1="\W \u\$ "
else
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
# User command aliases
alias useradd='sudo useradd'
alias usermod='sudo usermod'
alias userdel='sudo userdel'
# Other aliases
alias apachectl='sudo apachectl'
alias chkconfig='sudo chkconfig'
alias gpasswd='sudo gpasswd'
alias service='sudo service'
alias reboot='sudo reboot'
alias yum='sudo yum'
fi
if [[ -s $HOME/.rbenv ]] ; then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
fi
if which rbenv &>/dev/null; then
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007" ; echo $(rbenv version-name) | tr -d "\012" ; git branch --no-color 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/(\1)/" | tr -d "\012" ; echo'
else
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007" ; echo -n $GEM_HOME | sed -e "s/.*\///" | tr -d "\012" ; git branch --no-color 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/(\1)/" | tr -d "\012" ; echo'
fi
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi
# reverse search http://superuser.com/questions/159106/reverse-i-search-in-bash
stty -ixon
# colored grep
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;33'
# colored ls
export LSCOLORS='Gxfxcxdxdxegedabagacad'
## history ( http://d.hatena.ne.jp/sppr/20090109/1231518070 )
# Make bash append rather than overwrite the history on disk
shopt -s histappend
# Whenever displaying the prompt, write the previous line to disk and read unread history lines
#export PROMPT_COMMAND="history -a; history -n"
# increase history size
export HISTSIZE=100000
export SAVEHIST=100000
# Don't put duplicate lines in the history and don't save
export HISTCONTROL="ignoredups"
export HISTTIMEFORMAT="%F %T "
# alias rm='rm -i'
alias df='df -h'
alias sl=ls
alias la='ls -AF' # Compact view, show hidden
alias ll='ls -althr' # 'ls -al'
alias l='ls -a'
alias l1='ls -1'
alias q="exit"
alias ..='cd ..' # Go up one directory
alias ...='cd ../..' # Go up two directories
alias ....='cd ../../..' # Go up two directories
alias -- -="cd -" # Go back
alias stop='top -o CPU -s 5'
alias h='ghci'
alias hi='history'
alias historyc='history | cut -c8-'
alias historyd='history | cut -c8- | sed -e "s/^/$ /"'
# Tree
if [ ! -x "$(which tree 2>/dev/null)" ]
then
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
fi
alias utf='nkf -wd --overwrite'
alias utfhalf='nkf -xwd --overwrite'
alias utfall='find . -type f -name "*" -exec nkf -wd --overwrite {} \;'
alias sjis='nkf -s --overwrite'
alias multibyte='git ls-files | xargs nkf -g | grep -v -P "(ASCII|BINARY)" | grep -P "\.rb"'
#alias tarc='tar czvf'
#alias tarx='tar zxvf'
alias rspecf='rspec --only-failures'
alias rspecd='rspec --format documentation'
alias rbp='rails_best_practices -f html . ; open rails_best_practices_output.html'
alias db_migrate='bundle exec rake db:migrate ; RAILS_ENV=test bundle exec rake db:migrate'
alias db_rollback='bundle exec rake db:rollback ; RAILS_ENV=test bundle exec rake db:rollback'
alias db_drop='bundle exec rake db:drop ; RAILS_ENV=test bundle exec rake db:drop'
alias testdb_reset='RAILS_ENV=test bundle exec rake db:drop ; RAILS_ENV=test bundle exec rake db:migrate'
alias rmr='bundle exec rake nibs:clean && bundle exec rake resources'
alias rakeq='rake simulator args="-com.apple.CoreData.SQLDebug 1"'
alias rmlog='cat /Library/RubyMotion/NEWS'
alias rmib='rake ib:project && cp'
alias cdc='cd ~/current'
alias rvmc='rvm use ruby-1.8.7-p330@rails3'
alias rvms='rvm use system'
alias drvmc='rvm --default use ruby-1.8.7-p330@rails3'
alias drvms='rvm --default use system'
alias m=mate
alias g='git'
alias gut=git
alias got=git
alias gti=git
alias gst='git status'
alias gitst='git status'
alias gs='git status'
alias gpod='git pull --rebase origin develop'
alias gpom='git pull --rebase origin master'
alias grepconf='grep -e "^[^#]"'
# grep -rl "string" /path (recursive & files-with-matches)
alias greprl='ggrep -rl'
alias greprx='ggrep --exclude-dir=tmp --exclude-dir=log -r'
alias grepc='LANG=C ggrep'
alias pjson='python -mjson.tool'
alias cl='consular list'
alias ce='consular edit'
alias cs='consular start'
alias cc='consular create'
alias cst='consular start today'
alias tst='consular start today'
alias s='subl -w'
alias s2='subl2 -w'
alias sublc2='cd ~/Library/Application\ Support/Sublime\ Text\ 2/'
alias sublc='cd ~/Library/Application\ Support/Sublime\ Text\ 3/'
alias vb='vi ~/.bashrc'
alias mb='subl ~/.bashrc'
alias sb='source ~/.bashrc'
alias vbp='vi ~/.bash_profile'
alias mbp='subl ~/.bash_profile'
alias sbp='source ~/.bash_profile'
alias vg='vi ~/.gitconfig'
alias mg='subl ~/.gitconfig'
alias be='bundle exec'
alias brake='bundle exec rake'
alias beat='bundle exec autotest'
alias beats='SELENIUM=true bundle exec autotest'
alias bl='mv $HOME/.bundle_OFF $HOME/.bundle'
alias bloff='mv $HOME/.bundle $HOME/.bundle_OFF'
alias bapi_on='ruby -i -pe "gsub %r{^(source.*)https?://rubygems\.org(.*)}, '\''\1http://bundler-api.herokuapp.com/\2'\''" Gemfile'
alias bapi_off='ruby -i -pe "gsub %r{^(source.*)http://bundler-api\.herokuapp\.com/(.*)}, '\''\1https://rubygems.org\2'\''" Gemfile'
alias cap='bundle exec cap'
alias cap_orig='$GEM_HOME/bin/cap'
alias gem137='gem update --system 1.3.7'
alias gemlatest='gem update --system'
alias gemformat="perl -p -i -e 's/ 00:00:00.000000000Z//' ~/.rvm/gems/*/specifications/*.gemspec"
alias gemlistall='gem list --all --remote'
alias st='git sourcetree'
alias rbed='ruby-build --definitions'
alias rbeu='brew uninstall ruby-build && brew install --HEAD ruby-build'
alias rbev='rbenv versions'
alias rbei='rbenv install'
alias rber='rbenv rehash'
alias rbeg='rbenv global'
alias rbel='rbenv local'
alias rla=request-log-analyzer
function pps() {
if [[ -z "$@" ]];then
papertrail -f -g staging staging.log | perl -pe 's/^(.{15})(.)([\S]+)(.)([\S]+)/\e[1;35m\1\e[0m\2\e[1;33m\3\e[0m\4\e[0;36m\5\e[0m/g';
else
papertrail -f -g staging staging.log $@ | perl -pe 's/^(.{15})(.)([\S]+)(.)([\S]+)/\e[1;35m\1\e[0m\2\e[1;33m\3\e[0m\4\e[0;36m\5\e[0m/g' | perl -pe "s/($@)(.*)/\e[1;31m\1\e[0m\2/g";
fi
}
function ppe() {
papertrail -f -g $1 staging.log $2 | perl -pe 's/^(.{15})(.)([\S]+)(.)([\S]+)/\e[1;35m\1\e[0m\2\e[1;33m\3\e[0m\4\e[0;36m\5\e[0m/g' | perl -pe "s/($@)(.*)/\e[1;31m\1\e[0m\2/g";
}
function ppp() {
if [[ -z "$@" ]];then
papertrail -f -g production production.log | perl -pe 's/^(.{15})(.)([\S]+)(.)([\S]+)/\e[1;35m\1\e[0m\2\e[1;33m\3\e[0m\4\e[0;36m\5\e[0m/g';
else
papertrail -f -g production production.log $@ | perl -pe 's/^(.{15})(.)([\S]+)(.)([\S]+)/\e[1;35m\1\e[0m\2\e[1;33m\3\e[0m\4\e[0;36m\5\e[0m/g' | perl -pe "s/($@)(.*)/\e[1;31m\1\e[0m\2/g";
fi
}
function ppt() {
if [[ -z "$@" ]];then
echo "No \$@";
echo $@;
else
echo $@;
fi
}
# Usage $ cat log/production.log | rl
alias rl='grep Started | awk {'"'"'print $3'"'"'} | sed -e '"'"'s/[0-9][0-9]*/X/g'"'"'| sort | uniq -c | sort -rn'
alias freq='mask_path.rb | sort | uniq -c | sort -n | awk '"'"'$1>1 {print}'"'"''
alias freq2='mask_path.rb | sort | uniq -c | sort -n | awk '"'"'$1>1 {print}'"'"' | awk '"'"'$3 != "" {print}'"'"' | grep -v -P "(cd|git)"'
alias freq3='mask_path.rb | grep "|" | sort | uniq -c | sort -n | awk '"'"'$1>1 {print}'"'"''
alias redis-server-with-conf='redis-server /usr/local/etc/redis.conf'
alias selenium-server='java -jar /Applications/Selenium/selenium-server-standalone-2.21.0.jar -Dwebdriver.firefox.bin=/Applications/Firefox.app/Contents/MacOS/firefox-bin'
alias iphone='open /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app'
alias sim='open ~/Library/Application\ Support/iPhone\ Simulator/6.1/Applications/'
alias pgs='/usr/local/bin/postgres -D /usr/local/var/postgres'
# Engine yard
alias ey_production='ey status -e production | grep Commit | awk {'"'"'print $3'"'"'} | xargs git branch -lf ey_production && git log --graph --decorate --pretty=oneline --abbrev-commit -30 ey_production'
alias ey_staging='ey status -e staging | grep Commit | awk {'"'"'print $3'"'"'} | xargs git branch -lf ey_staging && git log --graph --decorate --pretty=oneline --abbrev-commit -30 ey_staging'
alias eyssh='ey ssh -e staging'
alias eysshdb='ey ssh -e staging --db-master'
function eysshs {
echo "Usage: $ eysshs 'ls /path/to/'"
ey ssh "echo \"### \`hostname\` ###\";$@" -e staging --all
}
function eysshproduction {
echo "Usage: $ eysshproduction 'ls /path/to/'"
ey ssh "echo \"### \`hostname\` ###\";$@" -e production --all
}
# Common Rails command shortcuts
# http://blog.envylabs.com/2010/07/common-rails-command-shortcuts/
function ss {
if [ -e script/rails ]; then
script/rails server $@
else
script/server $@
fi
}
function sc {
if [ -e script/rails ]; then
script/rails console $@
else
script/console $@
fi
}
function sg {
if [ -e script/rails ]; then
script/rails generate $@
else
script/generate $@
fi
}
function brewfix {
brew unlink $@ && brew link $@
}
function pg_dup {
if [[ -n "$2" ]];then
createdb -U $USER -O $USER -T $1 $2
else
echo "Usage: $ pg_dup copy_from copy_to"
fi
}
## http://hayne.net/MacDev/Bash/aliases.bash
#-----------
# Searching:
#-----------
# Searching bundle gems http://www.saturnflyer.com/blog/jim/2013/03/15/searching-through-your-bundled-gems
# Usage : $ agb textarea $ agb "form textarea"
agb () {
ag "$@" `bundle show --paths`
}
run() {
number=$1
shift
for i in `seq $number`; do
$@
done
}
# ff: to find a file under the current directory
ff () { /usr/bin/find . -name "$@" ; }
# ffs: to find a file whose name starts with a given string
ffs () { /usr/bin/find . -name "$@"'*' ; }
# ffe: to find a file whose name ends with a given string
ffe () { /usr/bin/find . -name '*'"$@" ; }
clear_git () {
find . | grep -p ".git$" | xargs rm -rf
}
# grepfind: to grep through files found by find, e.g. grepf pattern '*.c'
# note that 'grep -r pattern dir_name' is an alternative if want all files
grepfind () { find . -type f -name "$2" -print0 | xargs -0 grep "$1" ; }
# I often can't recall what I named this alias, so make it work either way:
alias findgrep='grepfind'
# find_larger: find files larger than a certain size (in bytes)
find_larger() { find . -type f -size +${1}c ; }
function sublg { bundle show $@ | xargs subl; }
# alias for AWS
alias ec2-start='ec2-run-instances'
alias ec2-stop='ec2-terminate-instances'
alias ec2-status='ec2-describe-instances'
alias ec2-auth='ec2-authorize default -p 22 && ec2-authorize default -p 80'
# Memo
# Restart Finder
# osascript -e 'tell app "Finder" to quit'
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then PATH=$PATH:$HOME/.rvm/bin ; fi # Add RVM to PATH for scripting
export PATH=$PATH:~/bin
export GOPATH=$HOME/go