sent-tools

A small toolkit of shell scripts for compiling suckless sent slideshows.
git clone https://scm.kuandu.systems/git-raw/sent-tools.git
Log | Files | Refs | README

compile-sentspec-wrapper.sh (1791B)


      1 #!/bin/sh
      2 #
      3 # Usage: ./compile-sentspec-wrapper.sh file.sentspec
      4 #
      5 # This script:
      6 #   - Checks that the input ends with .sentspec.
      7 #   - Converts the input to an output filename ending with .sent.
      8 #   - Optionally loads extra arguments from a 'config' file in the same directory.
      9 #   - Runs compile-sentspec with these options and writes output to the .sent file.
     10 #
     11 # Config file format:
     12 #   - Place a file named "config" in the script directory (optional).
     13 #   - To add options, define a shell function named compile_sentspec_args that
     14 #     prints each argument on its own line, for example:
     15 #
     16 #       compile_sentspec_args() {
     17 #         printf '%s\n' \
     18 #           -b black \
     19 #           -f '#00ff00' \
     20 #           -F 'Comic Neue Regular'
     21 #       }
     22 #
     23 #   - If no config or function is given, only the input file is used.
     24 
     25 set -eu
     26 
     27 case $1 in
     28   *.sentspec) ;;
     29   *)
     30     echo "Usage: $0 file.sentspec" >&2
     31     exit 1
     32     ;;
     33 esac
     34 
     35 status() {
     36     printf '[*] %s\n' "$*" >&2
     37 }
     38 
     39 specfile="$1"
     40 outfile="${specfile%.sentspec}.sent"
     41 
     42 # Source "config" (if it exists) for optional argument customization
     43 specdir=$(dirname -- "$specfile")
     44 CONFIG="$specdir/config"
     45 if [ -f "$CONFIG" ]; then
     46   status "Sourcing $CONFIG"
     47   # shellcheck disable=SC1090
     48   . "$CONFIG"
     49 
     50   # If the user provided a compile_sentspec_args function in config, use its output for options
     51   if command -v compile_sentspec_args > /dev/null 2>&1; then
     52     # shellcheck disable=SC2046
     53     set -- $(compile_sentspec_args)
     54     # Add the .sentspec file passed as the first arg to this script
     55     set -- "$@" "$specfile"
     56   else
     57     stauts "No compile_sentspec_args() found in config!"
     58   fi
     59 else
     60   status "No config file found"
     61 fi
     62 
     63 status "Calling: exec compile-sentspec $@ > $outfile"
     64 compile-sentspec "$@" > "$outfile" && status "Done"