Files
dotfiles/zshrc
2014-07-20 13:10:53 +02:00

245 lines
8.0 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
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/lib/io:~/.cabal/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info
export PYTHONSTARTUP=~/.pythonrc
export TERM=rxvt
alias gcc="gcc-mp-4.9"
alias g++="g++-mp-4.9"
alias qmake4="/opt/local/bin/qmake"
alias qmake="/usr/local/Qt-5.3.0/bin/qmake"
alias python="python3.3"
alias cdtan="cd ~/Documents/Code/Github/Detanglement/src"
alias cdpy="cd ~/Documents/Code/Github/AudioPython"
alias cdpc="cd ~/Documents/Code/PrivCode/"
alias cdl="cd ~/Documents/Code/LiveCodingEditor"
alias cdg="cd ~/Documents/Code/Github"
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 -la"
alias sloccount="sloccount --addlang makefile --addlang html --multiproject --duplicates --crossdups --autogen"
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
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) rar 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
}
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(){
cp ~/.bash_profile ~/Documents/Code/Github/.dotfiles/bash_profile
cp ~/.ghci ~/Documents/Code/Github/.dotfiles/ghci
cp ~/.gitignore ~/Documents/Code/Github/.dotfiles/gitignore
cp ~/.gitconfig ~/Documents/Code/Github/.dotfiles/gitconfig
cp ~/.pythonrc ~/Documents/Code/Github/.dotfiles/pythonrc
cp ~/.vimrc ~/Documents/Code/Github/.dotfiles/vimrc
cp ~/.zshrc ~/Documents/Code/Github/.dotfiles/zshrc
}
upgrade () {
if [ ! $1 ] ; then
print "local upgrade"
if [ `uname` = "Darwin" ]; then
print "osx_upgrade_local"
osx_upgrade_local
elif [ `uname -o` = "GNU/Linux" ]; then
print "debian_upgrade_local"
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
print "remote upgrade"
if [[ `ssh $1 uname -o 2&>/dev/null` = "GNU/Linux" ]] ; then
print "debian_upgrade_remote"
debian_upgrade_remote $1
elif [[ `ssh $1 uname 2&>/dev/null` = "Darwin" ]] ; then
print "osx_upgrade_remote"
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 () {
print "=== update Mac systems ==="
sudo softwareupdate -i -a
if [ -x /usr/local/bin/brew ] ; then
print "=== homebrew update ==="
brew update
brew upgrade
fi
if [ -x /sw/bin/fink ] ; then
print "=== fink upgrade ==="
sudo fink selfupdate
sudo fink update-all
sudo fink cleanup
fi
if [ -x /opt/local/bin/port ] ; then
print "=== darwin ports ==="
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
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
}
debian_upgrade_local (){
print "Upgrading Debian"
sudo apt-get update && sudo apt-get -u upgrade
print "Cleaning up"
sudo apt-get clean
}
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
print "=== update Mac systems ==="
ssh $1 -t /usr/bin/sudo /usr/sbin/softwareupdate -i -a
fi
if [[ $FINK_UP == "y" ]] ; then
print "=== fink upgrade ==="
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
print "=== darwin ports ==="
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
print "remote debian upgrade on $1"
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"
print "upgrade on $1 done"
fi
fi
}
function tree(){
find . | sed -e 's/[^\/]*\//|--/g' -e 's/-- |/ |/g' | $PAGER
}