-
Notifications
You must be signed in to change notification settings - Fork 0
/
mb_new_pic.sh
executable file
·59 lines (47 loc) · 1.5 KB
/
mb_new_pic.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# make a new entry for the microblog including a picture
# the picture should be a file in ~/microblog/images/ and should
# have been git added before you run this script
mb_location=$HOME/microblog/;
post_location=$mb_location"_posts";
# set up my variables
today=$(date +%F);
now=$(date +%F\ %H:%M);
iterator=1;
filename=$today-$(printf "%02d" $iterator).md;
cd $post_location;
# make sure we have the hottest newest latest
git pull;
# determine the first available file for today
while [ -f $filename ]
do iterator=$(($iterator+1));
filename=$today-$(printf "%02d" $iterator).md;
done
# pre-populate the file
# note on the <+markers+>: you can just start typing and enter your post
# text. Then hit ctrl+j and vim jumps to the the next marker and
# highlights it, so if you continue typing it'll be overwritten. Then
# hit ctrl+j again and so forth
echo "---
date: $now
---
![<+title+>]({{\"images/<+filename+>\"|absolute_url}} \"<+description+>\")
" > $filename;
# start editing
vim +star +4 $filename;
# and upload
git add $filename;
git commit -a -m $iterator;
git push;
# now create the necessary variables for tooting, one with the image filename,
# one with the image description and one with the toot text
imagefile=$(grep absolute_url $filename | cut -d \" -f 2);
description=$(grep absolute_url $filename | cut -d \" -f 4);
toot_txt=$(sed -n -e 4p $filename);
# aaaand toot toot!
cd $mb_location;
/usr/bin/toot post -m $imagefile -d "$description" "$toot_txt";
echo "
all done with $filename;
"