Created
January 17, 2012 21:22
-
-
Save techieshark/1628956 to your computer and use it in GitHub Desktop.
bashrc bits
This file contains hidden or 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
# Git | |
alias ga='git add' | |
alias gbs='git bisect' | |
alias gbl='git blame' | |
alias gb='git branch' | |
alias gco='git checkout' | |
alias gc='git commit' | |
alias gcl='git clone' | |
alias gcp='git cherry-pick' | |
alias gd='git diff' | |
alias gdc='git diff --cached' | |
alias gdm='git diff | mate' | |
alias gg='git log --pretty=oneline --abbrev-commit --graph --decorate' | |
alias gl='git log' | |
alias gm='git merge' | |
alias gp='git push' | |
alias grb='git rebase' | |
alias grs='git reset' | |
alias grm='git rm' | |
alias grv='git revert' | |
alias gsh='git show' | |
alias gs='git status' | |
alias gst='git stash' | |
alias gt='git tag' | |
alias gu='git update' | |
alias guc='git reset --soft HEAD^' |
This file contains hidden or 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
alias m="mate app config db/migrate db/seed.rb features Gemfile lib public spec test vendor/plugins &" | |
alias ra="rails application" | |
alias rc="rails console" | |
alias rb="rails benchmarker" | |
alias rd="rails destroy" | |
alias rdb="rails dbconsole" | |
alias rg="rails generate" | |
alias rn="rails new" | |
alias rp="rails profiler" | |
alias rr="rails runner" | |
alias rs="rails server" | |
alias post='psql -h localhost -U postgres' |
This file contains hidden or 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
# Misc. | |
alias a="alias | grep" # Use 'a foo' to search aliases for 'foo' | |
alias h=history | |
alias pandora=pianobar | |
# Development | |
if [ -f $BASHDIR/.bash.git.aliases ]; then | |
. $BASHDIR/.bash.git.aliases | |
fi | |
if [ -f $BASHDIR/.bash.rails.aliases ]; then | |
. $BASHDIR/.bash.rails.aliases | |
fi |
This file contains hidden or 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
# ~/.bashrc | |
# Location of Git repo with this and other bash related files: | |
BASHDIR=~/dev/bashrc | |
# If not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
###################### Path ############################## | |
export PATH=/usr/local/bin:${PATH}:~/apps:~/bin | |
###################### Aliases ########################### | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
alias cheats="cat $BASHDIR/bash-history-cheat-sheet.txt" | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
platform='unknown' | |
unamestr=`uname` | |
if [[ "$unamestr" == 'Linux' ]]; then | |
platform='linux' | |
elif [[ "$unamestr" == 'FreeBSD' ]]; then | |
platform='freebsd' | |
elif [[ "$unamestr" == 'Darwin' ]]; then | |
platform='mac' | |
fi | |
#if [[ $platform == 'linux' ]]; then | |
# alias ls='ls --color=auto' | |
if [ $platform == 'freebsd' -o $platform == 'mac' ]; then | |
alias ls='ls -G' | |
fi | |
# More specific aliases in .bash_aliases | |
if [ -f $BASHDIR/.bash_aliases ]; then | |
. $BASHDIR/.bash_aliases | |
fi | |
# Store personal / local aliases in ~/.bash_aliases | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
###################### Prompt & Window titles ############# | |
# Get git branch to show in prompt: | |
function parse_git_branch { | |
# http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/ | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
echo "("${ref#refs/heads/}")" | |
# Alternate code from http://www.lullabot.com/articles/git-best-practices-history-viewing-tips-and-displaying-branch-context | |
#git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
# Set prompt to e.g. "user@host:~/current/directory(master)$ " | |
PS1="\u@\h:\w\$(parse_git_branch)$ " | |
# Set window title of X terminals to e.g. 'user@host:~/current/directory' | |
case ${TERM} in | |
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix) | |
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"' | |
;; | |
screen) | |
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"' | |
;; | |
esac | |
###################### Misc Functions ##################### | |
# Function to allow 'up 3' instead of 'cd ../../..' | |
up () { | |
if [ -z $1 ]; then | |
cd .. | |
elif [ $1 -gt 0 ]; then | |
let count=0 | |
while [ $count -lt $1 ]; do | |
cd .. | |
let count=count+1 | |
done | |
else | |
echo "Argument must be a positive integer." | |
fi | |
} | |
# For Ruby / RVM | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* | |
# z makes jumping around easy. https://github.com/rupa/z | |
if [ -d ~/bin/z ]; then | |
. ~/bin/z/z.sh | |
fi | |
###################### Development #################### | |
# After `brew install git bash-completion`, we want to use bash completion on mac (Ubuntu is below) | |
if [ $platform == 'mac' ]; then | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi | |
fi | |
###################### Ubuntu Defaults #################### | |
# don't put duplicate lines in the history. See bash(1) for more options | |
# don't overwrite GNU Midnight Commander's setting of `ignorespace'. | |
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups | |
# ... or force ignoredups and ignorespace | |
HISTCONTROL=ignoreboth | |
# append to the history file, don't overwrite it | |
shopt -s histappend | |
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) | |
# check the window size after each command and, if necessary, | |
# update the values of LINES and COLUMNS. | |
shopt -s checkwinsize | |
# make less more friendly for non-text input files, see lesspipe(1) | |
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then | |
. /etc/bash_completion | |
fi | |
###################### Local Settings ##################### | |
if [ -f ~/.bashrc.local ] ; then | |
. ~/.bashrc.local | |
fi |
This file contains hidden or 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
These Bash dot-files help setup a sane development environment quickly. |
This file contains hidden or 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
.---------------------------------------------------------------------------. | |
| | | |
| Bash History Cheat Sheet | | |
| | | |
'---------------------------------------------------------------------------' | |
| Peteris Krumins ([email protected]), 2008.02.15 | | |
| http://www.catonmat.net - good coders code, great reuse | | |
| | | |
| Released under the GNU Free Document License | | |
'---------------------------------------------------------------------------' | |
===================== Emacs Keyboard Shortcut Summary ===================== | |
.--------------.------------------------------------------------------------. | |
| | | | |
| Shortcut | Description | | |
| | | | |
'--------------+------------------------------------------------------------' | |
| C-p | Fetch the previous command from the history list. | | |
'--------------+------------------------------------------------------------' | |
| C-n | Fetch the next command from the history list. | | |
'--------------+------------------------------------------------------------' | |
| M-< | Move to the first line in the history. | | |
'--------------+------------------------------------------------------------' | |
| M-> | Move to the end of the input history. | | |
'--------------+------------------------------------------------------------' | |
| C-r | Search backward starting at the current line (incremental) | | |
'--------------+------------------------------------------------------------' | |
| C-s | Search forward starting at the current line (incremental). | | |
'--------------+------------------------------------------------------------' | |
| M-p | Search backward using non-incremental search. | | |
'--------------+------------------------------------------------------------' | |
| M-n | Search forward using non-incremental search | | |
'--------------'------------------------------------------------------------' | |
======================= Vi Keyboard Shortcut Summary ====================== | |
.--------------.------------------------------------------------------------. | |
| | | | |
| Shortcut | Description | | |
| | | | |
'--------------+------------------------------------------------------------' | |
| k | Fetch the previous command from the history list. | | |
'--------------+------------------------------------------------------------' | |
| j | Fetch the next command from the history list. | | |
'--------------+------------------------------------------------------------' | |
| /string or | Search history backward for a command matching string. | | |
| CTRL-r | | | |
'--------------+------------------------------------------------------------' | |
| ?string or | Search history forward for a command matching string. | | |
| CTRL-s | (Note that on most machines Ctrl-s STOPS the terminal | | |
| | output, change it with `stty' (Ctrl-q to resume)). | | |
'--------------+------------------------------------------------------------' | |
| n | Repeat search in the same direction as previous. | | |
'--------------+------------------------------------------------------------' | |
| N | Repeat search in the opposite direction as previous. | | |
'--------------+------------------------------------------------------------' | |
| G | Move to history line N (for example, 15G). | | |
'--------------'------------------------------------------------------------' | |
======================== History Expansion Summary ======================== | |
Event Designators: | |
.--------------.------------------------------------------------------------. | |
| | | | |
| Designator | Description | | |
| | | | |
'--------------+------------------------------------------------------------' | |
| ! | Start a history substitution. | | |
'--------------+------------------------------------------------------------' | |
| !! | Refer to the last command. | | |
'--------------+------------------------------------------------------------' | |
| !n | Refer to the n-th command line (try `history' command). | | |
'--------------+------------------------------------------------------------' | |
| !-n | Refer to the current command line minus n. | | |
'--------------+------------------------------------------------------------' | |
| !string | Refer to the most recent command starting with 'string'. | | |
'--------------+------------------------------------------------------------' | |
| !?string? | Refer to the most recent command containing 'string'. | | |
'--------------+------------------------------------------------------------' | |
| ^str1^str2^ | Quick substitution. Repeat the last command, replacing | | |
| | 'str1' with 'str2'. | | |
'--------------+------------------------------------------------------------' | |
| !# | Refer to the entire command line typed so far. | | |
'--------------'------------------------------------------------------------' | |
Word Designators: | |
(Word designators follow the event designators, separated by a collon ':') | |
.--------------.------------------------------------------------------------. | |
| | | | |
| Designator | Description | | |
| | | | |
'--------------+------------------------------------------------------------' | |
| 0 | The zeroth (first) word in a line (usually command name). | | |
'--------------+------------------------------------------------------------' | |
| n | The n-th word in a line. | | |
'--------------+------------------------------------------------------------' | |
| ^ | The first argument (the second word) in a line. | | |
'--------------+------------------------------------------------------------' | |
| $ | The last argument in a line. | | |
'--------------+------------------------------------------------------------' | |
| % | The word matched by the most recent string search. | | |
'--------------+------------------------------------------------------------' | |
| x-y | A range of words from x to y (-y is synonymous with 0-y). | | |
'--------------+------------------------------------------------------------' | |
| * | All words but the zeroth (synonymous with 1-$). | | |
'--------------+------------------------------------------------------------' | |
| x* | Synonymous with x-$ | | |
'--------------+------------------------------------------------------------' | |
| x- | The words from x to the second to last word. | | |
'--------------'------------------------------------------------------------' | |
Modifiers (modifiers follow word designators, separated by a colon): | |
.--------------.------------------------------------------------------------. | |
| | | | |
| Modifier | Description | | |
| | | | |
'--------------+------------------------------------------------------------' | |
| h | Remove a trailing pathname component, leaving the head. | | |
'--------------+------------------------------------------------------------' | |
| t | Remove all leading pathname component, leaving the tail. | | |
'--------------+------------------------------------------------------------' | |
| r | Remove a trailing suffix of the form .xxx, leaving the | | |
| | basename. | | |
'--------------+------------------------------------------------------------' | |
| e | Remove all but the trailing suffix. | | |
'--------------+------------------------------------------------------------' | |
| p | Print the resulting command but do not execute it. | | |
'--------------+------------------------------------------------------------' | |
| q | Quotes the substituted words, escaping further | | |
| | substitutions. | | |
'--------------+------------------------------------------------------------' | |
| x | Quotes the substituted words, breaking them into words at | | |
| | blanks and newlines. | | |
'--------------+------------------------------------------------------------' | |
| s/old/new/ | Substitutes 'new' for 'old'. | | |
'--------------+------------------------------------------------------------' | |
| & | Repeats the previous substitution. | | |
'--------------+------------------------------------------------------------' | |
| g | Causes s/old/new/ or & to be applied over the entire | | |
| | event line. | | |
'--------------'------------------------------------------------------------' | |
============ History Behavior Modification via Shell Variables ============ | |
.----------------.----------------------------------------------------------. | |
| | | | |
| Shell Variable | Description | | |
| | | | |
'----------------+----------------------------------------------------------' | |
| HISTFILE | Controls where the history file gets saved. | | |
| | Set to /dev/null not to save the history. | | |
| | Default: ~/.bash_history | | |
'----------------+----------------------------------------------------------' | |
| HISTFILESIZE | Controls how many history commands to keep in HISTFILE | | |
| | Default: 500 | | |
'----------------+----------------------------------------------------------' | |
| HISTSIZE | Controls how many history commands to keep in the | | |
| | history list of current session. | | |
| | Default: 500 | | |
'----------------+----------------------------------------------------------' | |
| HISTIGNORE | Controls which commands to ignore and not save to the | | |
| | history list. The variable takes a list of | | |
| | colon separated values. Pattern & matches the previous | | |
| | history command. | | |
'----------------'----------------------------------------------------------' | |
============ History Behavior Modification via `shopt' Command ============ | |
.----------------.----------------------------------------------------------. | |
| | | | |
| shopt Option | Description | | |
| | | | |
'----------------+----------------------------------------------------------' | |
| histappend | Setting the variable appends current session history to | | |
| | HISTFILE. Unsetting overwrites the file each time. | | |
'----------------+----------------------------------------------------------' | |
| histreedit | If set, puts a failed history substitution back on the | | |
| | command line for re-editing. | | |
'----------------+----------------------------------------------------------' | |
| histverify | If set, puts the command to be executed after a | | |
| | substitution on command line as if you had typed it. | | |
'----------------'----------------------------------------------------------' | |
shopt options can be set by a `shopt -s option' and | |
can be unset by a `shopt -u option'. | |
=============================== Examples ================================== | |
$ echo a b c d e (executes `echo ab c d e`) | |
a b c d e | |
$ echo !!:3-$ (executes `echo c d e`) | |
c d e | |
$ echo !-2:*:q (executes `echo 'a b c d e'`) | |
a b c d e | |
$ echo !-3:1:2:4:x (executes `echo 'a' 'b' 'd'`) | |
a b d | |
$ echo !-4:1-3:s/a/foo/:s/b/bar/:s/c/baz/ (executes `echo foo bar baz`) | |
foo bar baz | |
$ tar -xzf package-x.y.z.tgz | |
... | |
$ cd !-1:$:r (executes `cd package-x.y.z`) | |
package-x.y.z $ | |
$ ls -a /tmp | |
file1 file2 file3 ... | |
$ ^-a^-l^ (executes `ls -l /tmp`) | |
-rw------- 1 user user file1 | |
... | |
=========================================================================== | |
.---------------------------------------------------------------------------. | |
| Peteris Krumins ([email protected]), 2008.02.15 | | |
| http://www.catonmat.net - good coders code, great reuse | | |
| | | |
| Released under the GNU Free Document License | | |
'---------------------------------------------------------------------------' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment