Frequently accessed directories
export blog=/usr/local/google/home/jefferyyuan/jeffery/doc/blog
alias cdb="cd /usr/local/google/home/jefferyyuan/jeffery/doc/blog"
alias gdrive='cd ~/Google\ Drive'
alias cd1="cd .."
alias cd2="cd ../.."
alias cd3="cd ../../.."
alias cd4="cd ../../../.."
alias cd5="cd ../../../../.."
alias cd6="cd ../../../../../.."
Command Shortcuts
alias open=xdg-open
alias atb=atom-beta
alias markdownToHtml=/home/jefferyyuan/jeffery/doc/blog/resource/script/markdownToHtml.sh
alias q=exit
alias c=clear
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias ping='ping -c 5'
alias bashrc='atb ~/.bashrc'
alias reloadbash='source ~/.bashrc'
alias pserver='python -m SimpleHTTPServer 8000'
alert alias for long running commands
- usage:
sleep 5; alert
Compatible with commands from other OS
If we have scripts that were originated written for MacOS, now we want to run it in another Linux System: for example, Debian. Some commands like “pbcopy and pbpaste” are only available in Mac. We can change the code to detect which command it should use like below:
Or we can just define alias in .bashrc:
function pbcopy () {
xsel --clipboard --input "$@"
}
function pbpaste () {
xsel --clipboard --output "$@"
}
Command Options
# Let there be color in grep!
export GREP_OPTIONS=' — color=auto'
# Set Atom-Beta as the default editor
export EDITOR="atom-beta --wait"
# http://bashrcgenerator.com/
# only show current directory
export PS1="\w \[$(tput sgr0)\]"
Better Bash History
# append to the history file rather than overwrite it
shopt -s histappend
HISTSIZE=9999999
HISTFILESIZE=9999999
# Store and reload the history immediately
PROMPT_COMMAND="PROMPT_COMMAND; history -a; history -c; history -r;"
# use one command per line
shopt -s cmdhist
HISTTIMEFORMAT="%h %d %H:%M:%S "
HISTCONTROL=ignorespace:erasedups
HISTIGNORE="history"
SSH Hosts
.bashrc vs .bash_profile
- .bash_profile: runs when user logins in the shell
- .bashrc: runs every time when user opens a new terminal
- Mac OS X’s Terminal runs a login shell by default for each new terminal window
Organize .basrch
- Put .bashrc (and other dotfiles) under version control.
- Make .bashrc a symlink to a place which we keep under version control
split .bashrc
- make a ~/profile.d directory, and source it in .bashrc:
- example: bash_aliases.sh