Skip to content

Instantly share code, notes, and snippets.

@soxofaan

soxofaan/pre-receive

Created Sep 23, 2013
Embed
What would you like to do?
Git pre-receive hook to entertain the pusher with a random fact
#!/bin/sh
# Echo a random fun fact for the pusher's pleasure.
rand=$(( $RANDOM % 5 ))
case "$rand" in
0)
echo "--- Did you know? randomfunfacts.com says: -----------------------------------"
wget --timeout=1 randomfunfacts.com/ -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;"
echo "------------------------------------------------------------------------------"
;;
1)
echo "--- Did you know? http://numbersapi.com/random/trivia says: ------------------"
curl --max-time 1 http://numbersapi.com/random/trivia 2>/dev/null
echo
echo "------------------------------------------------------------------------------"
;;
2)
echo "--- Did you know? http://numbersapi.com/random/math says: --------------------"
curl --max-time 1 http://numbersapi.com/random/math 2>/dev/null
echo
echo "------------------------------------------------------------------------------"
;;
3)
echo "--- Did you know? http://randomfactgenerator.net says: -----------------------"
curl --max-time 1 --silent http://randomfactgenerator.net/ 2>/dev/null | ruby -e "puts (/<div id='z'>(.*?)<br/.match(\$stdin.read)[1])"
echo "------------------------------------------------------------------------------"
;;
4)
url=$( date +http://numbersapi.com/%m/%d/date )
echo "--- Did you know? $url says: ---------------------"
curl --max-time 1 --silent $url 2>/dev/null
echo
echo "------------------------------------------------------------------------------"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.