Created
September 12, 2017 16:50
-
-
Save ia/5dfd641e96167eb33daa5c14f693e5f4 to your computer and use it in GitHub Desktop.
LEGACY: simpe script for posting in twitter/juick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#* | |
#* twitsh - twitting/juicking from terminal | |
#* Copyright (C) 2008,2009 ia | |
#* | |
#* twitsh is free software. | |
#* | |
#* You may redistribute it and/or modify it under the terms of the | |
#* GNU General Public License, as published by the Free Software | |
#* Foundation; either version 3 of the License, or (at your option) | |
#* any later version. | |
#* | |
#* toolchain is distributed in the hope that it will be useful, | |
#* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
#* See the GNU General Public License for more details. | |
#* | |
#* You should have received a copy of the GNU General Public License | |
#* along with main.c. If not, write to: | |
#* The Free Software Foundation, Inc., | |
#* 51 Franklin Street, Fifth Floor | |
#* Boston, MA 02110-1301, USA. | |
#* | |
VERSION="twitsh - twitting/juicking last shell command from terminal | |
version 0.1 | |
Copyright (C) 2008-2009 ia | |
This is free software; see the source for copying conditions. There is NO | |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." | |
USAGE="usage: twitsh [options] [text]"; | |
INFO="twitsh - twitting/juicking last shell command(by default) from terminal | |
usage: twitsh [options] [text] | |
basic options: | |
-t [y/n] post to twitter | |
-j [y/n] post to juick (via pidgin) | |
-r set and create new config file | |
-v show version of script | |
-h show info of script" | |
settings () | |
{ | |
echo "Creating config file for twitsh..." | |
password1="somepassword"; | |
password2="otherpassword"; | |
read -p "Enter login name for your twitter's account: " login; | |
while [ "$save_password" != "y" ] && [ "$save_password" != "n" ]; do | |
read -s -n1 -p "Save password for your twitter's account in config file? (y/n): " save_password; printf "\n"; | |
done | |
if [ "$save_password" == "y" ]; then | |
while [ "$password1" != "$password2" ]; do | |
read -s -p "Enter password for your twitter's account: " password1; printf "\n"; | |
read -s -p "Repeat password for your twitter's account: " password2; printf "\n"; | |
if [ "$password1" != "$password2" ]; then echo "Entered passwords don't match."; fi; | |
done | |
password="$password1"; | |
fi | |
while [ "$twitting" != "y" ] && [ "$twitting" != "n" ]; do | |
read -s -n1 -p "Twitting by default? (y/n): " twitting; printf "\n"; | |
done | |
while [ "$juicking" != "y" ] && [ "$juicking" != "n" ]; do | |
read -s -n1 -p "Juicking by default? (y/n): " juicking; printf "\n"; | |
done | |
shell="`echo "$SHELL" | cut -d "/" -f 3-`"; | |
shell_config=."$shell"rc; | |
histfile="`cat $shell_config | grep "^HISTFILE" | cut -d "=" -f 2- | sed 's/\~/\/home\/'"$USER"'/'`" | |
if [ "$histfile" == "$NULL" ]; then | |
while [ -f "$histfile" ]; do | |
read -p "Enter full path to your history file: " histfile; | |
if [ -f "$histfile" ]; then echo "Sorry. File $histfile is not available."; fi; | |
done | |
fi | |
read -p "Enter prompt symbol of command line (eg.$,>,etc.): " symbol; | |
printf "#config file for twitsh script for twitting/juicking from command line\n\nhistfile=\"$histfile\"\nsymbol=\"$symbol \"\n\ntwitting=$twitting\nlogin=\"$login\"\nsave_password=$save_password\npassword=\"$password\"\n\njuicking=$juicking\n" > $config; | |
echo "Done."; | |
echo "$INFO" | |
} | |
twit () | |
{ | |
chars=`echo "$text" | wc -m`; | |
if [ "$chars" -gt 140 ]; then | |
echo "Message for twitting too long."; return 1; | |
fi; | |
if [ "$save_password" == n ]; then read -s -p "Enter password for your twitter's account: " password; printf "\n"; fi; | |
text="`echo "$text" | tr '!' '.'`"; | |
report=`curl -s -u $login:$password -d status="$text" http://twitter.com/statuses/update.xml`; | |
error_auth=`printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <request>/statuses/update.xml</request>\n <error>Could not authenticate you.</error>\n</hash>\n"`; | |
if [[ "$report" != "$error_auth" ]]; then | |
echo "Message has been successfully twitted."; | |
return 0; | |
else | |
echo "Error within twitting last message."; | |
return 1; | |
fi | |
} | |
juick () | |
{ | |
if [ "`ps ax | grep pidgin | grep -v grep`" == "$NULL" ]; then echo "Pidgin is not running."; return 1; fi; | |
purple-remote "jabber:[email protected]&message=$text"; | |
if [[ "$?" == 0 ]]; then | |
echo "Message has been successfully juicked."; | |
return 0; | |
else | |
echo "Error within juicked last message."; | |
return 1; | |
fi | |
} | |
init_settings () | |
{ | |
if [ -f "$config" ]; then | |
. "$config"; | |
else | |
settings; | |
. "$config"; | |
fi | |
return 0; | |
} | |
args_check () | |
{ | |
while getopts t:j:rvh option; do | |
#setting up additional options | |
case $option in | |
t ) | |
case "$OPTARG" in | |
y ) twitting="$OPTARG";; | |
n ) twitting="$OPTARG";; | |
* ) echo "Available options for -t: y,n"; exit 0 ;; | |
esac;; | |
j ) | |
case "$OPTARG" in | |
y ) juicking="$OPTARG";; | |
n ) juicking="$OPTARG";; | |
* ) echo "Available options for -j: y,n"; exit 0 ;; | |
esac;; | |
r ) settings; exit 0 ;; | |
v ) echo "$VERSION"; exit 0 ;; | |
h ) echo "$INFO"; exit 0 ;; | |
* ) echo "$USAGE"; exit 0 ;; | |
esac | |
done | |
shift $(($OPTIND-1)); | |
text="$*"; | |
return 0; | |
} | |
Main () | |
{ | |
config=/home/"$USER"/.twitshrc; | |
init_settings; | |
args_check "$@"; | |
if [ "$text" == "$NULL" ]; then | |
line=`cat $histfile | wc -l`; | |
cmd=`cat $histfile | sed -ne $(($line-1))p`; | |
text="$symbol$cmd"; | |
fi | |
if [ "$twitting" != "n" ]; then twit; fi; | |
if [ "$juicking" != "n" ]; then juick; fi; | |
return 0; | |
} | |
Main "$@" | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment