//How to post code snippets from the command line (contributes are welcome!)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 function help () {
16 echo "Usage: "`basename $0`" -u <username> [-P, -D ]";
17 }
18 while getopts "u:p:PdhH" opt;
19 do
20 case $opt in
21 u ) user=$OPTARG;;
22 p ) pass=$OPTARG ;;
23 P ) private=1;;
24 'h' | 'H' ) help ;;
25 * ) help ;;
26 esac
27 done
28
29 shift $(($OPTIND-1))
30
31 if [ -z $1 ]
32 then echo -e "What I am supposed to upload?\n missing filename... exiting"; exit 1
33 fi
34 if [ -z $user ]
35 then
36 echo -e "How am I supposed to log-in without your user name?\n";help
37 exit 1
38 fi
39 if [ -z $pass ]
40 then read -p "password: " pass
41
42 fi
43 if [ -z $1 ]
44 then echo "Missing file to upload; exiting";exit 1
45 fi
46 if [ -z $private ];then private=1
47 fi
48
49
50 curl -v -D /tmp/header -F "username=$user" -F "password=$pass" -l "http://www.bigbold.com/snippets/account/login" &> /dev/null
51
52 userid=$(curl -b /tmp/header -l http://www.bigbold.com/snippets/ 2> /dev/null |grep -Eo 'post\[user_id\]\" value\=\"[0-9]{1,9}"' | sed -r 's/post\[user_id\]" value="([0-9]{1,9})"/\1/')
53
54 if [ $? = 1 ]
55 then echo -e "autentication failture, or unable to get userid!\n Exiting"; exit 1
56 fi
57
58 read -p "snippet title: " snip_title
59 read -p "description: " snip_desc
60 read -p "tags:" tags
61
62 snip='//'${snip_desc}'code'`cat $1`'/code'
63
64 curl -b /tmp/header.txt -F "post[id]= " -F "post[user_id]=$userid" -F "post[title]=$snip_title" -F "post[content]=$snip" -F "post[tag_list]=$tags" -F "post[private]=1" http://www.bigbold.com/snippets/posts/create/ &> /dev/null
65
66 curl -b /tmp/header "http://www.bigbold.com/snippets/logout" &> /dev/null