From 5ab4f60b0b8fa6eae686b224cbb1c94ee04ea89a Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 10 Feb 2022 19:27:56 +0100 Subject: [PATCH] gemtext-index --- gemtext-index.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 gemtext-index.sh diff --git a/gemtext-index.sh b/gemtext-index.sh new file mode 100755 index 0000000..0c36b2d --- /dev/null +++ b/gemtext-index.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Create a Gemtext index from the files in the directory and their main title. +# Spaces in file names are escaped (but not tabs or other heresies). + +usage() { + echo "Usage: $0 [-h] [DIR]" + echo "Print a Gemtext index of the directory." + echo " -h show usage" + echo " DIR use this directory instead of the working dir" +} + +[[ "$1" == "-h" ]] && usage && exit 0 + +DIR="${1:-.}" +for file in "$DIR"/*.gmi; do + title="$(head -n 1 "$file" | cut -c 3-)" + echo "=> ${file// /%20} $title" +done