Cookbook

Auto-completion in git

$ brew install bash-completion

# ~/.bash_profile
if [ -f ~/.git-completion.bash ]; then
    . ~/.git-completion.bash
fi

Git optimizations

# Delete merged local branches
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

# Delete all remote branches that are not on origin
git fetch -p

# Clean and optimize repository
git gc --aggressive

Clear all Bash history

alias clear_history="cat /dev/null > ~/.bash_history && history -c && exit"

Delete all temporary Emacs files

alias clean='find . \( -name '\''*~'\'' -or -name '\''.*~'\'' \) -exec echo {} > /tmp/trash.temp \; ;cat /tmp/trash.temp; echo '\''Really want to delete theses files ? [y/n] '\''; read response; if [ $response = y ]; then cat /tmp/trash.temp | xargs -I {} rm '\''{}'\''; echo '\''Files deleted'\''; else echo '\''Files not deleted'\''; fi; rm -f /tmp/trash.temp;'

Rails various aliases

# Play with `bundle`
alias be="bundle exec"
alias ber="bundle exec rake"
alias bet="bundle exec ruby -Itest"

# When having problems with db/structure.sql:
# `git checkout db/structure.sql` then `dblol`
alias dblol="ber db:drop db:create db:structure:load db:seed"

alias rk="QUEUE=* bundle exec rake resque:work"
alias allpdftoxml="ls *.pdf | xargs -I{} pdftohtml -xml {} {}.xml"

Various aliases

alias emacs='emacsclient -t' # Run emacs in server mode
alias ne='emacsclient -t' # Shorter alias for emacs
alias grep='grep --colour=auto' # Grep with colors
alias l='ll'
alias ll='ls -laG'
alias ls='ls -G'
alias rm='rm -i' # Always confirm a `rm`
alias timestamp='date +"%s"'

thefuck gem

# I use it for this example, but it can do a lot more.
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

$ fuck
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...
brew install thefuck

# ~/.bash_profile
eval "$(thefuck --alias)"