Showing posts with label shellscript. Show all posts
Showing posts with label shellscript. Show all posts

Friday, June 13, 2008

Zshfully Yours, Gem Shortcuts

Stephen Celis provided a slick bash-method for quickly opening and browsing RDocs, over at his blog. I have merely ported the function to zsh. As a slight modification, $BROWSER and $BROWSER_OPTIONS are used instead of just open, so it works cross platform. The code:



gemdoc() {
local gemdir=`gem env gemdir`
$BROWSER $BROWSER_OPTIONS $gemdir/doc/`ls $gemdir/doc/ | grep $1 | sort | tail -1`/rdoc/index.html
}

_gemdoc() {
compadd $(ls `gem env gemdir`/doc)
}

compdef _gemdoc gemdoc

Wednesday, June 4, 2008

Script for removing orphans in Arch Linux

Shell scripting is fun, so I created a small function that removes all orphaned packages as reported by Pacman. It calls itself recursively if removing the current orphans revealed any new ones. Tested with zsh since that is my personal preference the best shell around :) - but it probably runs under bash as well. Here is the code:


remove_orphans() {
for pkg in `pacman -Qdt|awk -F ' ' '{ printf("%s\n", $1) }'`; do
sudo pacman -R $pkg
done
if [ `pacman -Qdt|wc -l` -gt 0 ]; then remove_orphans; fi
}