#! /bin/bash

############################################################################################
#
# sbwg-addtag	Script to add a line to the beginning of one or multiple files, meant to use
# 		to add a tag to an entry or page source file for SBWG from v0.8 onwards.
# Version: 0.0.2
# Last edited: 2022-03-28
#
############################################################################################


if [ $# -lt 2 ]; then
  printf '\nThis script adds a tagline to the beginning of one or multiple SBWG source'
  printf ' files.\n\nUsage:\n %s TAGLINE FILE[S]\n\nTAGLINE is the line (string) ' "$0"
  printf 'that you would like to add.\nFILE[S] is the name(s) or path(s) and name(s) '
  printf 'of one or multiple files to which you would like to add the tagline\n\n'
  printf 'Multiple taglines can be added by including a newline character in the '
  printf 'string.\n\nExamples:\n'
  printf '%s lang:en entries/*\n' "$0"
  printf '%s "cat:Dogs Are Great" ~/myblog/entries/Dog*\n' "$0"
  printf '%s top:Boating "The Summer Of 2021"\n' "$0"
  exit 1
fi

tagline="${1}"
shift
for file in "${@}"; do
  sed -i "1s/^/${tagline}\n/" "${file}"
done
