blob: b5a668d21e4337e00ba3084fa88acc18ce894d40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# Read random pastes from pastie.org ;)
#!/usr/bin/env sh
echo Fetching paste list ...
lst=`wget pastie.org/pastes -q -O - | grep "id='paste" | head -n 1 | sed "s/.*id='paste_\([0-9]*\)'.*/\1/"`
echo Newest paste is $lst.
r=""
while :; do
rnd="$(ruby -e "$><<1+rand($lst)")"
echo -e "\n"Looking up paste $rnd ...
wget http://www.pastie.org/pastes/$rnd/download -q -O /tmp/paste-$rnd
if [ -s "/tmp/paste-$rnd" ]; then
grep -q "<p class=\"notice\">Sorry, there is no pastie #$rnd or it has been removed\. Why not create a new pastie?</p>" /tmp/paste-$rnd
if [ "$?" = "0" ]; then
echo Paste $rnd does not exist.
else
clear
more /tmp/paste-$rnd
echo -ne "\n\nSave $rnd?[n] "
read r
[ "$r" = "y" ] && echo Saving as paste $rnd in $HOME && cp /tmp/paste-$rnd $HOME
fi;
else
echo Empty paste.
fi;
rm /tmp/paste-$rnd
echo -n Quit?[n]\
read r
[ "$r" = "y" ] && exit
done;
|