Files
dotfiles/zshrc
2016-06-02 12:09:20 +02:00

415 lines
13 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/veitheller/.zshrc'
zle_highlight=(default:bold)
autoload -Uz compinit -D && compinit
autoload -U promptinit && promptinit
autoload -U colors && colors
autoload -Uz VCS_INFO_get_data_git && VCS_INFO_get_data_git 2> /dev/null
setopt prompt_subst
# 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 GOPATH=~/.go
export GOBIN=$GOPATH/bin
export GHC_HOME=/usr/local/bin
export CABAL_HOME=$HOME/.cabal/
export PATH=$GHC_HOME:$CABAL_HOME/bin:$PATH:/opt/local/bin:/usr/local/sbin:~/.cabal/bin:/usr/local/opt/llvm/bin:$GOBIN
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 LANG=en_US.UTF-8
export LC_ALL=$LANG
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
alias dob="git branch --merged | grep -vE '(\*)|(master)|(dev)' | xargs -n 1 git branch -d"
alias vi="stty stop '' -ixoff ; vim"
alias gcc="gcc-5"
alias g++="g++-5"
alias psh="perl ~/.scripts/psh"
alias push="git push"
alias pull="git pull"
alias pupgrade2="pip2.7 install --upgrade pip; python2.7 ~/.pip-upgrade 2"
alias pupgrade3="pip3 install --upgrade pip; python3 ~/.pip-upgrade 3"
alias pupgrade="pupgrade2 && pupgrade3"
alias cupgrade="cabal update; cabal list --simple-output --installed | awk '{print $1}' | uniq | sed 's/ .*$//' | xargs -I {} cabal install {} --reinstall"
alias ghci="ghci -v0"
alias ghc-sandbox="ghc -no-user-package-db -package-db .cabal-sandbox/*-packages.conf.d"
alias ghci-sandbox="ghci -no-user-package-db -package-db .cabal-sandbox/*-packages.conf.d"
alias runhaskell-sandbox="runhaskell -no-user-package-db -package-db .cabal-sandbox/*-packages.conf.d"
alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
alias python="python3"
alias pysh="ipython"
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 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 cdgo="cd ~/.go/src"
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 --read-lang-def=/Users/veitheller/.scripts/cloc-z.txt *"
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 tmv="tmux split-window"
alias tmh="tmux split-window -h"
alias tms="tmux select-pane -t"
alias tmk="killall tmux; tmux"
PROMPT="%{$fg_bold[red]%}%n%{$fg_no_bold[white]%} at %{$fg_bold[green]%}%m%{$fg_no_bold[white]%}"$'\n'"=> "
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
function rprompt-git-current-branch {
local name st color gitdir action
if [[ "$PWD" =~ '/\.git(/.*)?$' ]]; then
return
fi
name=`git rev-parse --abbrev-ref=loose HEAD 2> /dev/null`
if [[ -z $name ]]; then
return
fi
gitdir=`git rev-parse --git-dir 2> /dev/null`
action=`VCS_INFO_git_getaction "$gitdir"` && action="($action)"
st=`git status 2> /dev/null`
if [[ -n `echo "$st" | grep "ahead of"` ]]; then
color=%F{white}
elif [[ -n `echo "$st" | grep "^nothing to"` ]]; then
color=%F{green}
elif [[ -n `echo "$st" | grep "^no changes added"` ]]; then
color=%F{yellow}
elif [[ -n `echo "$st" | grep "^# Changes to be committed"` ]]; then
color=%B%F{red}
else
color=%B%F{blue}
fi
echo "on %{$fg_bold[white]%}$color$name$action%f%b %{$reset_color%}"
}
function cabal_sandbox_info() {
cabal_files=(*.cabal(N))
if [ $#cabal_files -gt 0 ]; then
if [ -f cabal.sandbox.config ]; then
echo "%{$fg_no_bold[white]%} is %{$fg_bold[green]%}sandboxed%{$reset_color%}"
else
echo "%{$fg_no_bold[white]%} is %{$fg_bold[red]%}not sandboxed%{$reset_color%}"
fi
fi
}
RPROMPT='`rprompt-git-current-branch`'
RPROMPT+="%{$fg[white]%}in %{$fg_bold[yellow]%}%~%{$reset_color%}"
RPROMPT+='`cabal_sandbox_info`'
function ghc-pkg-reset() {
read 'ans?erasing all your user ghc and cabal packages - are you sure (y/n) ? '
if [[ "$ans" =~ ^[Yy]$ ]] ; then
echo 'erasing directories under ~/.ghc'; rm -rf `find ~/.ghc -maxdepth 1 -type d`; \
echo 'erasing ~/.cabal/lib'; rm -rf ~/.cabal/lib; \
# echo 'erasing ~/.cabal/packages'; rm -rf ~/.cabal/packages; \
# echo 'erasing ~/.cabal/share'; rm -rf ~/.cabal/share; \
fi
}
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 -r ~/.cabal/config ${DOTPATH}cabal/
cp -r ~/.scripts ${DOTPATH}
cp ~/.bash_profile ${DOTPATH}bash_profile
cp ~/.cardinalrc ${DOTPATH}cardinalrc
cp ~/.ghci ${DOTPATH}ghci
cp ~/.gitconfig ${DOTPATH}gitconfig
cp ~/.gitignore ${DOTPATH}gitignore
cp ~/.inputrc ${DOTPATH}inputrc
cp ~/.pip-upgrade ${DOTPATH}pip-upgrade
cp ~/.pythonrc ${DOTPATH}pythonrc
cp ~/.tmux.conf ${DOTPATH}tmux.conf
cp ~/.valgrindrc ${DOTPATH}valgrindrc
cp ~/.vimrc ${DOTPATH}vimrc
cp ~/.zeptorc ${DOTPATH}zeptorc
cp ~/.zshrc ${DOTPATH}zshrc
}
makepass(){
LEN=20
if [ $# > 1 ] ; then
LEN=$1
fi
cat /dev/urandom | base64 | head -c $LEN
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 --all
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-###
function zeptosay () {
x=`fortune`
zepto ~/.scripts/zeptosay.zp $x
}
fortune | zeptosay
#source ~/.zshrc.priv