Added useful functions to zshrc

This commit is contained in:
Veit Heller
2014-07-20 13:10:53 +02:00
parent eb77a41d84
commit be2fcac84e

155
zshrc
View File

@@ -103,31 +103,6 @@ pinfo(){
top -pid `pgrep $1 | tr "\\n" "," | sed 's/,$//' | sed -e's/,/ -pid /g'` top -pid `pgrep $1 | tr "\\n" "," | sed 's/,$//' | sed -e's/,/ -pid /g'`
} }
update(){
autoload -U colors && colors
yellow=$fg_no_bold[yellow]
none=$reset_color
if [[ $1 == '-v' ]] ; then
echo -e "${yellow}Updating homebrew formulae${none}"
brew update
echo -e "${yellow}Updating installed sources(Homebrew)${none}"
brew upgrade outdated
echo -e "${yellow}Updating MacPorts (sudo required)${none}"
sudo port selfupdate
echo -e "${yellow}Updating installed sources(MacPorts)${none}"
sudo port upgrade outdated
else
echo -e "${yellow}Updating homebrew formulae${none}"
brew update &> /dev/null
echo -e "${yellow}Updating installed sources(Homebrew)${none}"
brew upgrade outdated &> /dev/null
echo -e "${yellow}Updating MacPorts (sudo required)${none}"
sudo port selfupdate &> /dev/null
echo -e "${yellow}Updating installed sources(MacPorts)${none}"
sudo port upgrade outdated &> /dev/null
fi
}
save_dotfiles(){ save_dotfiles(){
cp ~/.bash_profile ~/Documents/Code/Github/.dotfiles/bash_profile cp ~/.bash_profile ~/Documents/Code/Github/.dotfiles/bash_profile
cp ~/.ghci ~/Documents/Code/Github/.dotfiles/ghci cp ~/.ghci ~/Documents/Code/Github/.dotfiles/ghci
@@ -137,3 +112,133 @@ save_dotfiles(){
cp ~/.vimrc ~/Documents/Code/Github/.dotfiles/vimrc cp ~/.vimrc ~/Documents/Code/Github/.dotfiles/vimrc
cp ~/.zshrc ~/Documents/Code/Github/.dotfiles/zshrc 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
}