draft (898B)
1 #!/bin/sh 2 3 # use arg as title and set post file path 4 TITLE=$1 5 RND=$2 6 7 if [ "$RND" = "mov" ] || [ "$RND" = "lit" ] ; then 8 ENTRY="entry/rnd.${RND}.rec:_${TITLE}.md" 9 else 10 ENTRY="entry/${TITLE}.md" 11 fi 12 13 # checkout the correct branch 14 if [ "$RND" = "mov" ] || [ "$RND" = "lit" ] ; then 15 git checkout -q rnd.${RND}.rec 16 git merge main 17 elif [ "$TITLE" == "main" ] ; then 18 echo "on main branch" 19 exit 1 20 else 21 git branch | grep ${TITLE} && \ 22 git checkout -q ${TITLE} || \ 23 $(git checkout -q main && git checkout -q -b ${TITLE}) || exit 1 24 fi 25 26 # if post file does not exist yet touch it 27 [ -f "${ENTRY}" ] || { 28 touch "${ENTRY}" 29 30 cat << EOF >> ${ENTRY} 31 --- 32 title: ??? 33 keywords: [??, ??, ??] 34 ... 35 EOF 36 } 37 38 # open post file in favourite editor 39 nvim "${ENTRY}" 40 41 # when vim closes add and commit the changes 42 # if there are any 43 git status | grep "${ENTRY}" || exit 0 44 git add "${ENTRY}" 45 git commit -S -m "${TITLE}"