Wednesday, April 10, 2013

IHATEYOU.SH

You may have repressed it, but remember the "climax" of Episode 3, where Anakin, full of rage, screams "I HATE YOU!" at Obi-Wan?



Wasn't that great?!  Truly Oscar-worthy.  If only we could replicate that utter rage when things go wrong in our terminal.  We can, thanks to IHATEYOU.SH!

#!/bin/bash
#Needed to provide alias expansion (so we can use those aliases after the script's finished)
shopt -s expand_aliases
while read x;
do
a=`echo $x | tr '[:lower:]' '[:upper:]'`;
#Added because the script was picking up empty lines
if [ "$a" != '' ]
then
alias $a=$x;
fi
done < <(compgen -c)
view raw IHATEYOU.sh hosted with ❤ by GitHub
This script uses bash's builtin compgen to list all of the commands available at the time, then iterates through that list, adding an all-caps alias.  These aliases will be local to your shell, so you don't have to worry about screwing up your pretty ~/.bash_aliases file.

To get rid of the aliases, either close the terminal session or apologize with the youareprettyok.sh script.

No comments:

Post a Comment