Shift builtin functions to main script so user scripts are easier
authorMira Ayre <mi@boxin.space>
Sat, 16 Jan 2021 02:47:16 +0000 (02:47 +0000)
committerMira Ayre <mi@boxin.space>
Fri, 9 Jul 2021 19:41:31 +0000 (20:41 +0100)
lib/core.sh [deleted file]
ssg

diff --git a/lib/core.sh b/lib/core.sh
deleted file mode 100644 (file)
index efa62a9..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-function include() { # include a file
-       # include FILE
-       cat "$1"
-}
-
-function index() { # index current directory
-       for f in .. ./* ; do
-               name="$(basename "$f")"
-               [[ "$(stat -c %F "$f")" == "directory" ]] && name+='/'
-
-               # omit .cf and PREFIX/POSTFIX files
-               [[ "$name" == *.cf ]] && continue
-               [[ "$name" == "PREFIX" ]] && continue
-               [[ "$name" == "POSTFIX" ]] && continue
-
-               printf "%s <a href=\"%s\">%s</a>%$((34 - ${#name}))s %-17s %16s<br/>" \
-                       "$(stat -c %A "$f")" \
-                       "$name" "$name" "" \
-                       "$(date '+%d-%m-%Y %H:%M' -d "@$(stat -c %Y "$f")")" \
-                       "$(stat -c %s "$f")"
-       done
-}
-
-function indexh() { # index with header
-       printf "<b>---------- %-34s %-17s %16s</b><br/>" "name" "date" "size"
-       index
-}
-
-function git-history() {
-       git log --follow --format='%h %ad: %s<br/>' \
-               --date='format:%d-%m-%Y' "$FILE" \
-               | tr -d "\n"
-}
-
-function title() { # custom title using $FILE
-       echo "<title>$1$(basename "$FILE" | rev | cut -d'.' -f2- | rev)$2</title>"
-}
diff --git a/ssg b/ssg
index 5abdd63a9b60d4ac9cd9fbfcf2894c48f86eb3ab..16ecd473420b014adf99e97d7a75c5d38bf72c56 100755 (executable)
--- a/ssg
+++ b/ssg
@@ -26,7 +26,51 @@ cd $dir
 echo "Working in '$(pwd)'" > /dev/stderr
 file="$(basename "$1")"
 
-# load stock functions
+# stock functions
+
+function include() { # include a file
+       # include FILE
+       cat "$1"
+}
+
+function index() { # index current directory
+       for f in .. ./* ; do
+               name="$(basename "$f")"
+               [[ "$(stat -c %F "$f")" == "directory" ]] && name+='/'
+
+               # omit .cf and PREFIX/POSTFIX files
+               [[ "$name" == *.cf ]] && continue
+               [[ "$name" == "PREFIX" ]] && continue
+               [[ "$name" == "POSTFIX" ]] && continue
+
+               printf "%s <a href=\"%s\">%s</a>%$((34 - ${#name}))s %-17s %16s<br/>" \
+                       "$(stat -c %A "$f")" \
+                       "$name" "$name" "" \
+                       "$(date '+%d-%m-%Y %H:%M' -d "@$(stat -c %Y "$f")")" \
+                       "$(stat -c %s "$f")"
+       done
+}
+
+function indexh() { # index with header
+       printf "<b>---------- %-34s %-17s %16s</b><br/>" "name" "date" "size"
+       index
+}
+
+function git-history() {
+       git log --follow --format='%h %ad: %s<br/>' \
+               --date='format:%d-%m-%Y' "$FILE" \
+               | tr -d "\n"
+}
+
+function title() { # title
+       echo "<title>$1</title>"
+}
+
+function titlef() { # custom title using $FILE
+       echo "<title>$1$(basename "$FILE" | rev | cut -d'.' -f2- | rev)$2</title>"
+}
+
+# load user functions
 libdir="${XDG_DATA_HOME:-$HOME/.local/share}/ssg"
 echo "Loading libraries from '$libdir'" > /dev/stderr
 for f in $libdir/** ; do