Files
dotfiles/zshrc
2015-03-27 16:37:59 +01:00

328 lines
10 KiB
Bash

# The following lines were added by compinstall
zstyle ':completion:*' completer _expand _complete _ignored _approximate
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:]}={[:upper:]}' 'r:|[._-_]=** r:|=**' ''
zstyle :compinstall filename '/Users/sidharta/.zshrc'
autoload -Uz compinit -D
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.zsh_history
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory autocd extendedglob nomatch notify
bindkey -e
# End of lines configured by zsh-newuser-install
export PATH=$PATH:/opt/local/bin:/usr/local/sbin:~/.cabal/bin
export MANPATH=$MANPATH:/opt/local/share/man:/usr/local/opt/erlang/lib/erlang/man
export INFOPATH=$INFOPATH:/opt/local/share/info
export PYTHONSTARTUP=~/.pythonrc
export NODE_PATH=/usr/local/lib/node_modules
export TERM=rxvt
export LC_ALL=$LANG
alias ..="cd .."
alias gcc="gcc-4.9"
alias g++="g++-4.9"
alias pupgrade2="python2.7 ~/.pip-upgrade 2"
alias pupgrade3="python3.4 ~/.pip-upgrade 3"
alias pupgrade="pupgrade2 && pupgrade3"
alias cupgrade="cabal update; cabal list --simple-output --installed | awk '{print $1}' | uniq | xargs -I {} cabal install {} --reinstall"
alias ghci="ghci -v0"
alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
alias qmake="/usr/local/Cellar/qt5/5.3.2/bin/qmake"
alias lupdate="/usr/local/Cellar/qt5/5.3.2/bin/lupdate"
alias lrelease="/usr/local/Cellar/qt5/5.3.2/bin/lrelease"
alias python="python3.4"
alias pip2="/usr/local/bin/pip"
alias pip="pip3"
alias pypy="pypy3"
alias setjdk="launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk"
alias cdtan="cd ~/Documents/Code/Github/Detanglement/src/server/detanglement"
alias cdpy="cd ~/Documents/Code/Github/AudioPython"
alias cdl="cd ~/Documents/Code/Github/VetoLC"
alias cdz="cd ~/Documents/Code/Github/zepto"
alias cdg="cd ~/Documents/Code/Github"
alias cdd="cd ~/Documents/Code/Github/decode"
alias cdot="cd ~/Documents/Code/Github/.dotfiles"
alias cdh="cd ~/Documents/Code/Github/hiss"
alias cdw="cd ~/Documents/Code/Work"
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl"
alias dud="du -d 1"
alias loc="cloc *"
alias ls="ls -a"
alias quit="exit"
alias howmuch="git ls-tree -r -z --name-only HEAD -- . | xargs -0 -n1 git blame --line-porcelain HEAD | grep '^author '| sort | uniq -c | sort -nr"
alias clipboard_clear="echo lol | pbcopy"
alias sloccount="sloccount --addlang makefile --addlang html --multiproject --duplicates --crossdups --autogen"
alias vlc="/Applications/VLC.app/Contents/MacOS/VLC"
PROMPT="[%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg_no_bold[yellow]%}%1~%{$reset_color%}]\$"
expand-or-complete-with-dots(){
echo -n "e[31m.....\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "Î" expand-or-complete-with-dots
precmd () {print -Pn "\e]2; %~/ \a"}
preexec () {print -Pn "\e]2; %~/ \a"}
insert_sudo () {
zle beginning-of-line; zle -U "sudo "
}
zle -N insert-sudo insert_sudo
bindkey "^[s" insert-sudo
case $TERM in
xterm*)
precmd(){print -Pn "\e]0;%m: %~\a"}
ssh(){
PRENAME="`dcop $KONSOLE_DCOP_SESSION sessionName`";
dcop "$KONSOLE_DCOP_SESSION" renameSession "$@";
/usr/bin/ssh "$@";
dcop "$KONSOLE_DCOP_SESSION" renameSession "$PRENAME"
} ;;
esac
extract(){
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.tar.xz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) if [ -n $2 ] ; then
unzip $1 -d $2
else
unzip $1
fi;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
mcd(){
mkdir -p $1
cd $1
}
netinfo(){
echo "--------------- Network Information ---------------"
/sbin/ifconfig | awk /'inet addr/ {print $2}'
/sbin/ifconfig | awk /'Bcast/ {print $3}'
/sbin/ifconfig | awk /'inet addr/ {print $4}'
/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
echo "${myip}"
echo "---------------------------------------------------"
}
pinfo(){
top -pid `pgrep $1 | tr "\\n" "," | sed 's/,$//' | sed -e's/,/ -pid /g'`
}
save_dotfiles(){
local DOTPATH=~/Documents/Code/Github/.dotfiles/
cp ~/.bash_profile ${DOTPATH}bash_profile
cp ~/.ghci ${DOTPATH}ghci
cp ~/.gitignore ${DOTPATH}gitignore
cp ~/.gitconfig ${DOTPATH}gitconfig
cp ~/.pythonrc ${DOTPATH}pythonrc
cp ~/.valgrindrc ${DOTPATH}valgrindrc
cp ~/.vimrc ${DOTPATH}vimrc
cp ~/.zshrc ${DOTPATH}zshrc
cp ~/.pip-upgrade ${DOTPATH}pip-upgrade
}
makepass(){
cat /dev/urandom | base64 | head -c 20
echo ''
}
massif(){
valgrind --tool=massif --massif-out-file=massif.prof $1 && ms_print massif.prof | less
}
upgrade () {
if [ ! $1 ] ; then
if [ `uname` = "Darwin" ]; then
osx_upgrade_local
elif [ `uname -o` = "GNU/Linux" ]; then
debian_upgrade_local
else
print "I don't know what can I do for this type of machine"
fi
elif [[ $1 = "help" || $1 = "--help" || $1 = "-h" ]] ; then
print "local usage for upgrading Mac OS X or debian systems including fink and darwin ports: upgrade and clean"
print 'remote usage: upgrade $debian_server'
elif [ $1 ]; then
if [[ `ssh $1 uname -o 2&>/dev/null` = "GNU/Linux" ]] ; then
debian_upgrade_remote $1
elif [[ `ssh $1 uname 2&>/dev/null` = "Darwin" ]] ; then
osx_upgrade_remote $1
else
print "$1 is not a debian nor an osx machine"
print "please implement an upgrade function for this kind of machine!"
fi
fi
}
osx_upgrade_local () {
if [ -x /usr/local/bin/brew ] ; then
brew update
brew upgrade
brew cleanup
fi
if [ -x /sw/bin/fink ] ; then
sudo fink selfupdate
sudo fink update-all
sudo fink cleanup
fi
if [ -x /opt/local/bin/port ] ; then
sudo port -d selfupdate
sudo port -ucRvpt upgrade installed
sudo port clean --all installed
if [ -x /opt/local/bin/gem ] ; then
sudo /opt/local/bin/gem update
fi
sudo port uninstall inactive
fi
if [ -d /Library/Application\ Support/TextMate/Bundles ]; then
pushd /Library/Application\ Support/TextMate/Bundles
svn up *.tmbundle
popd
osascript -e 'tell app "TextMate" to reload bundles'
fi
pupgrade
cupgrade
}
debian_upgrade_local (){
sudo apt-get update && sudo apt-get -u upgrade
sudo apt-get clean
pupgrade
cupgrade
}
osx_upgrade_remote (){
if [ ! $1 ]; then
print "usage: osx_upgrade_remote $osx_server"
print "Perhaps you want osx_upgrade_local ?"
else
local OSX_UP
local FINK_UP
local DARWINPORTS_UP
until [[ $OSX_UP == 'y' || $OSX_UP == 'n' ]]; do
print -n "Process osx upgrade on $1 (y/n)?"
read -q OSX_UP
done;
until [[ $FINK_UP == 'y' || $FINK_UP == 'n' ]]; do
print -n "Process fink upgrade on $1 (y/n)?"
read -q FINK_UP
done;
until [[ $DARWINPORTS_UP == 'y' || $DARWINPORTS_UP == 'n' ]]; do
print -n "Process darwinports upgrade on $1 (y/n)?"
read -q DARWINPORTS_UP
done;
if [[ $OSX_UP == "y" ]] ; then
fi
if [[ $FINK_UP == "y" ]] ; then
ssh $1 -t /usr/bin/sudo /sw/bin/fink selfupdate
ssh $1 -t /usr/bin/sudo /sw/bin/fink update-all
ssh $1 -t /usr/bin/sudo /sw/bin/fink cleanup
fi
if [[ $DARWINPORTS_UP == "y" ]] ; then
ssh $1 -t /usr/bin/sudo /opt/local/bin/port selfupdate
ssh $1 -t /usr/bin/sudo /opt/local/bin/port upgrade installed
ssh $1 -t /usr/bin/sudo /opt/local/bin/port clean --all installed
fi
fi
}
debian_upgrade_remote (){
if [ ! $1 ]; then
print "usage: debian_upgrade_remote $debian_server"
print "Perhaps you want debian_upgrade_local ?"
else
ssh $1 -t sudo apt-get update
ssh $1 -t "sudo apt-get -s upgrade"
local dummy
print -n "Process the upgrade y/n ?"
read -q dummy
if [[ $dummy == "y" ]] ; then
ssh $1 -t "sudo apt-get -u upgrade --yes && sudo apt-get clean"
fi
fi
}
function tree(){
find . | sed -e 's/[^\/]*\//|--/g' -e 's/-- |/ |/g' | $PAGER
}
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
#
COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
export COMP_WORDBREAKS
if type complete &>/dev/null; then
_npm_completion () {
local si="$IFS"
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
npm completion -- "${COMP_WORDS[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
complete -o default -F _npm_completion npm
elif type compdef &>/dev/null; then
_npm_completion() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
compdef _npm_completion npm
elif type compctl &>/dev/null; then
_npm_completion () {
local cword line point words si
read -Ac words
read -cn cword
let cword-=1
read -l line
read -ln point
si="$IFS"
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
COMP_LINE="$line" \
COMP_POINT="$point" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
compctl -K _npm_completion npm
fi
###-end-npm-completion-###