From bec43bccba699cbbd287bdeee5a2bcdd4dd19c85 Mon Sep 17 00:00:00 2001 From: Dominic Ricottone Date: Fri, 20 Dec 2024 17:01:02 +0000 Subject: [PATCH] Adding documents scripts --- Makefile | 4 ++ documents/Makefile | 4 ++ documents/hugo-bump | 1 + documents/hugo-extract-timestamp | 48 ++++++++++++++++++++ documents/hugo-timestamp | 75 ++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100755 documents/hugo-extract-timestamp create mode 100755 documents/hugo-timestamp diff --git a/Makefile b/Makefile index 237eaed..144294b 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ install: $(call subdir_make,archives,install) $(call subdir_make,containers,install) $(call subdir_make,display,install) + $(call subdir_make,documents,install) $(call subdir_make,emulation,install) $(call subdir_make,games,install) $(call subdir_make,network,install) @@ -24,6 +25,7 @@ uninstall: $(call subdir_make,archives,uninstall) $(call subdir_make,containers,uninstall) $(call subdir_make,display,uninstall) + $(call subdir_make,documents,uninstall) $(call subdir_make,emulation,uninstall) $(call subdir_make,games,uninstall) $(call subdir_make,network,uninstall) @@ -34,6 +36,7 @@ test: clean $(call subdir_make,archives,test) $(call subdir_make,containers,test) $(call subdir_make,display,test) + $(call subdir_make,documents,test) $(call subdir_make,emulation,test) $(call subdir_make,games,test) $(call subdir_make,network,test) @@ -44,6 +47,7 @@ clean: $(call subdir_make,archives,clean) $(call subdir_make,containers,clean) $(call subdir_make,display,clean) + $(call subdir_make,documents,clean) $(call subdir_make,emulation,clean) $(call subdir_make,games,clean) $(call subdir_make,network,clean) diff --git a/documents/Makefile b/documents/Makefile index c273393..0e2000b 100644 --- a/documents/Makefile +++ b/documents/Makefile @@ -6,13 +6,17 @@ COMP_DIR?=/usr/local/etc/bash_completion.d install: install -m755 hugo-bump $(BIN_DIR)/hugo-bump + install -m755 hugo-extract-timestamp $(BIN_DIR)/hugo-extract-timestamp install -m755 hugo-date $(BIN_DIR)/hugo-date install -m755 hugo-post $(BIN_DIR)/hugo-post + install -m755 hugo-timestamp $(BIN_DIR)/hugo-timestamp uninstall: rm $(BIN_DIR)/hugo-bump rm $(BIN_DIR)/hugo-date + rm $(BIN_DIR)/hugo-extract-timestamp rm $(BIN_DIR)/hugo-post + rm $(BIN_DIR)/hugo-timestamp test: bats test/ diff --git a/documents/hugo-bump b/documents/hugo-bump index 16c689e..53ec134 100755 --- a/documents/hugo-bump +++ b/documents/hugo-bump @@ -45,5 +45,6 @@ for filename in "${positional[@]}"; do fi done +# exit with accumulated error code exit "$code" diff --git a/documents/hugo-extract-timestamp b/documents/hugo-extract-timestamp new file mode 100755 index 0000000..0258f64 --- /dev/null +++ b/documents/hugo-extract-timestamp @@ -0,0 +1,48 @@ +#!/bin/bash + +name="hugo-extract-timestamp" +version="1.0" +read -r -d '' help_message <<-EOF + Extract a date/timestamp from a Hugo content files + Usage: hugo-extract-timestamp [OPTIONS] [TARGETS ..] + Options: + -h, --help print this message and exit + -q, --quiet suppress error messages + -v, --verbose show additional messages + -V, --version print version number and exit +EOF + +source /usr/local/lib/mylib.bash +. /usr/local/lib/myparse.bash + +# if no filenames given +if [[ ${#positional[@]} -eq 0 ]]; then + usage_msg +fi + +code=0 +newdate="$(hugo-date)" +for filename in "${positional[@]}"; do + + # if filename does not exist + if [[ ! -f "$filename" ]]; then + nonfatal_error_msg "No such file '$filename'" + code=1 + + # if filename does not contain timestamp + elif ! /usr/bin/grep --quiet "$filename" --regexp="^date:"; then + if [[ "$verbose" -eq 1 ]]; then + debug_error_msg "No timestamp in '$filename'" + fi + /usr/bin/echo + code=1 + + # main routine + else + /usr/bin/grep "$filename" --regexp="^date:" | /usr/bin/sed --expression="s/^date: *//" + fi +done + +# exit with accumulated error code +exit "$code" + diff --git a/documents/hugo-timestamp b/documents/hugo-timestamp new file mode 100755 index 0000000..7f5e901 --- /dev/null +++ b/documents/hugo-timestamp @@ -0,0 +1,75 @@ +#!/bin/bash + +name="hugo-timestamp" +version="1.0" +read -r -d '' help_message <<-EOF + Set a date/timestamp into a Hugo content files + Usage: hugo-timestamp [OPTIONS] TARGET DATETIME + Options: + -h, --help print this message and exit + -q, --quiet suppress error messages + -v, --verbose show additional messages + -V, --version print version number and exit +EOF + +source /usr/local/lib/mylib.bash +. /usr/local/lib/myparse.bash + +# error if no filenames given +if [[ ${#positional[@]} -lt 2 ]]; then + usage_msg +fi + +_ed_append_date() { + ed -s "$1" <