Linux. Google cli Blogger post with vim editor

Linux. Google cli Blogger post with vim editor


Source - http://nonblocking-random.blogspot.com/2010/06/blogger-editing-via-editor-googlecl.html
Thanks for solutions!!!



My version has next differences:
1. Ask before post.
2. First line must be TITLE.
3. Second line must be list of tags with comma delimeter and before post 2 line will be deleted.


############################################################

#!/bin/bash

GOOGLE=/usr/bin/google
BLOGFILE=$(mktemp)
EDITOR=$(which vim)

edit_post() {
${EDITOR} ${BLOGFILE}
echo "Ready to post ? y/n"
read ANSWER
case "${ANSWER}" in
n) edit_post ;;
N) edit_post ;;
esac
}

parse() {

TITLE=$( cat ${BLOGFILE} | head -n 1)
TAGS=$( cat ${BLOGFILE}| head -n 2 | tail -n 1)
sed --in-place '2d' ${BLOGFILE}

echo " TITLE -> ${TITLE}"
echo "TAGS - > ${TAGS}"

}

post_notes() {
${GOOGLE} blogger post --title "${TITLE}" --tags "${TAGS}" --src "${BLOGFILE}"
rm -fv ${BLOGFILE}
}

main() {
echo "API - ${GOOGLE}"
echo "EDITOR - ${EDITOR}"
echo "TMP file - ${BLOGFILE}"
echo "1 line of text -> TITLE "
echo "2 line of text -> TAGS "

sleep 1
edit_post
parse
post_notes
}

main