#! /bin/bash

############################################################################################
#
# 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.1
# Last edited: 2020-05-05
#
############################################################################################


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

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