Skip to content

Instantly share code, notes, and snippets.

@tinyheero
Last active August 29, 2015 14:23
Show Gist options
  • Save tinyheero/3a0bcd6fadd6ce8b3a87 to your computer and use it in GitHub Desktop.
Save tinyheero/3a0bcd6fadd6ce8b3a87 to your computer and use it in GitHub Desktop.
My ~/.bashrc
#----------
# Aliases
#----------
alias ls="ls -F"
alias pd="pushd"
alias bd="popd"
alias less="less -N"
alias rsync="rsync -a --verbose --partial --progress"
alias make="make --warn-undefined-variables"
#----------
# Environment variables
#----------
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Change prompt display
export PS1="\u@\h [\t] \w >> "
#----------
# hh program configuration
# https://github.com/dvorka/hstr
#----------
export HH_CONFIG=hicolor # get more colors
shopt -s histappend # append new history items to .bash_history
export HISTCONTROL=ignorespace # leading space hides commands from history
export HISTFILESIZE=10000 # increase history file size (default is 500)
export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)
export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}" # mem/file sync
# if this is interactive shell, then bind hh to Ctrl-r
if [[ $- =~ .*i.* ]]; then bind '"\C-r": "hh \C-j"'; fi
#----------
# Base16 Shell
# https://github.com/chriskempson/base16-shell
#----------
BASE16_SHELL="$HOME/.config/base16-shell/base16-default.dark.sh"
[[ "$-" == *i* ]] && [[ -s $BASE16_SHELL ]] && source $BASE16_SHELL
#----------
# Functions
#----------
# Handy Extract Program.
function extract(){
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $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) xz -d $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# cd to the path of the front Finder window
# http://brettterpstra.com/2013/02/09/quick-tip-jumping-to-the-finder-location-in-terminal/
cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
# auto-complete ssh hosts
# reads from the ~/.ssh/known_hosts file
_complete_ssh_hosts () {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
cat ~/.ssh/config | \
grep "^Host " | \
awk '{print $2}'
`
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur))
return 0
}
complete -F _complete_ssh_hosts ssh
# figure out whether to go vim in a tmux sessions (used for vim-r-plugin)
function vi(){
file_ext=$(echo $@ | awk -F . '{if (NF>1) {print $NF}}')
if [ "$file_ext" == "Rmd" -o "$file_ext" == "R" ]; then
if ["x$DISPLAY" == "x"]; then
tmux new-session "vim --servername VIM $@"
else
tmux -2 new-session "TERM=screen-256color vim --servername VIM $@"
fi
else
vim $@
fi
}
# count number of columns in file
function countCol(){
awk -F' ' '{print NF; exit}' $1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment