updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / zentwitter / zentwitter
blob0f9b81e47b1540689abe83154e1160c142bfd5d8
1 #!/bin/bash
2 ## @author Michael Klier <chi@chimeric.de>
3 # @www http://www.chimeric.de/pojects/ZenTwitter
4 ## Multi-user support by Isengrin L. Feuille <Autumnspeech@gmail.com>
5 # trivial twitter status update client
7 # main script
8 URL="https://twitter.com/statuses/update.xml"
9 ZENITY=/usr/bin/zenity
10 CURL=/usr/bin/curl
11 ZTRC=~/.zentwitterrc
12 SED=/bin/sed
14 if [ ! -f $ZTRC ] ;
15 then
16 USER=$(${ZENITY} --entry --text="You haven't configured Zentwitter, enter your username" --title="ZenTwitter")
17 while [[ $(echo "${USER}" | tr -d ' ') == "" ]];
19 USER=$(${ZENITY} --entry --text="D'oh! You entered nothing! Write your username again or check if it's in ~/.zentwitterrc:" --title="ZenTwitter")
20 if [[ "$?" == 1 ]];
21 then
22 exit 0
24 done
26 PASS=$(${ZENITY} --entry --text="Now enter your password" --title="ZenTwitter")
27 while [[ $(echo "${PASS}" | tr -d ' ') == "" ]];
29 PASS=$(${ZENITY} --entry --text="D'oh! You entered nothing! Write your password again or check if it's in ~/.zentwitterrc:" --title="ZenTwitter")
30 if [[ "$?" == 1 ]];
31 then
32 exit 0
34 done
35 echo $USER > $ZTRC
36 echo $PASS >> $ZTRC
37 else
38 USER=$(${SED} -n 1p $ZTRC)
39 PASS=$(${SED} -n 2p $ZTRC)
42 # check if zenity is installed
43 if [[ ! -x $ZENITY ]];
44 then
45 echo "ERROR: Zenity is missing!"
46 exit 1
49 # check if curl is installed
50 if [[ ! -x $CURL ]];
51 then
52 $ZENITY --error --text="ERROR: curl is missing" --title="ZenTwitter"
53 exit 1
56 # check if sed is installed
57 if [[ ! -x $SED ]];
58 then
59 $ZENITY --error --text="ERROR: sed is missing" --title="ZenTwitter"
60 exit 1
63 # get tweet & update status
64 if [ $# != 0 ]; then
65 export tweet="$*";
68 if [ $# = 0 ]; then
69 export tweet=$(${ZENITY} --entry --text="Gimme your tweet:" --title="ZenTwitter")
72 while [[ $(echo "${tweet}" | tr -d ' ') == "" ]];
74 tweet=$(${ZENITY} --entry --text="D'oh! You entered nothing! Try again or cancel:" --title="ZenTwitter")
75 if [[ "$?" == 1 ]];
76 then
77 exit 0
79 done
81 export count=`echo "$tweet" | wc -m`;
83 if [ $count -gt 140 ]; then
84 $ZENITY --error --text="Your status was over 140 characters." --title="ZenTwitter"
85 exit;
88 if [ -z "$tweet" ]; then
89 $ZENITY --error --text="Your status wasn't changed." --title="ZenTwitter"
90 exit;
91 else
92 $CURL -u ${USER}:${PASS} -d status="${tweet}" -d source="ZenTwitter" -s ${URL}
95 if [[ "$?" == 1 ]];
96 then
97 exit 0
100 if [[ "$?" == 0 ]];
101 then
102 # $ZENITY --info --text="Updated successful!" --title="ZenTwitter"
103 exit 0
104 else
105 $ZENITY --error --text="Something went wrong!\nRun ZenTwitter from a commandline for more information!" --title="ZenTwitter"
106 exit 1