💾 Archived View for spool-five.com › gemlog › 2021-04-01-second_script.gmi captured on 2022-03-01 at 15:10:01. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Second Shell Script - Autolog

I joined Cosmic Voyage a while back. I really love the system there for updating you ship's posts. You type 'log' at the command line and you are presented with a series of options for logging your entry.

This morning, I decided to try out something similar for logging gemini posts.

I did look at the script for the Cosmic Voyage log command, but it was a bit too complicated for me (!).

So, I tried to just put together something as simply as I could (I am still so new to the shell and I have no technical experience outside of linux).

The script just:

- asks for a title, appends that title to the gemlog index,

- then, asks for a 'commit' message, appends that to my nanolog file

- finally, asks for a 'tag', and adds the post to the tag page.

It seems to work okay. It was really useful learning how to search for a string with sed, and then add the entry to the next line.

Still to do:

- Better user feedback, but the 'interactive' aspects of shell script still seemed too advanced for me

- At the moment it searches for a 'month' string in the gemlog index, and then adds the post below that. So, I have to manually add the 'month' title to the index (e.g., have to add 'April' before I can post the first April post). It would be great if it could automatically do that if it was missing, and even if it could sort the posts into month/year directories. I did find someone who did something like that with their gemini capsule, but I haven't figured out how to integrate it yet:

https://www.hughrundle.net/how-to-write-a-static-site-generator-in-30-lines-or-less/

- In general, I have to make it more 'flexible'. I'm not sure how it handles incorrect input, etc.

Anyway, here is the script if anyone's interested:


#!/bin/sh
DIR="/home/eoin/gemini/"

[ -z "$1" ] && exit
echo "Title: "
read title
# Inserts log entry in index, under current month
sed -i "/\\$(date +'%B')/a => $1 $(date +'%Y-%d-%m') - $title" $DIR/gemlog/index.gmi

echo "Commit Message:"
read msg
# updates microlog
sed -i "9i## $(date +'%a %d %b %Y %H:%M %Z')\n$msg\n" $DIR/micro.gmi

# Inserts entry in tag section of gemlog
echo "Tag:"
read tag
[ -z $tag ] && exit

if [[ "$tag" = "Meta" ]]; then
  sed -i "/\# Meta/a => $1 $title" $DIR/gemlog/tags.gmi
elif [[ "$tag" = "Reading" ]]; then
  sed -i "/\# Reading/a => $1 $title" $DIR/gemlog/tags.gmi
elif [[ "$tag" = "Scavenge" ]]; then
  sed -i "/\# Scavenge/a => $1 $title" /$DIR/gemlog/tags.gmi
elif [[ "$tag" = "Journal" ]]; then
  sed -i "/\\$(date +'%B')/a => $1 $title" /$DIR/gemlog/tags.gmi
fi

Gemlog