#!/usr/bin/env bash if ! hash uuidgen 2>/dev/null; then echo >&2 "... uuidgen dependency not met. Please install." exit 1 fi declare INCLUDEDIR="$2/doc/source/_includes" declare -A charReplacements # max basename lenght *before* appending UUID declare MAX_LEN=62 charReplacements=( ["-"]="minus" ["+"]="plus" ["\@"]="at" ["\&"]="and" ) ask_name () { echo -e "`cat < "${outdir}/${filename}.${ext}" if [[ -f ${outdir}/${filename}.${ext} ]]; then echo -e "\nCreated ${outdir}/${filename}.${ext}" exit 0 else exit 1 fi } WD=$1 myuuid=$(uuidgen) # Keep as fallback? # myuuid="$(od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}')" myuuid="${myuuid:24:35}" ask_name strike=$(for ((i=1; i<=${#title}; i++)); do printf '=%.0s' "$i" done) ask_type filename=${title} for c in "${!charReplacements[@]}" do filename=`sed "s/$c/${charReplacements[$c]}/g" <<< $filename` done if [[ ${#filename} -gt ${MAX_LEN} ]]; then filename=${filename:0:$MAX_LEN} declare FULL_LEN=$(($MAX_LEN + 13)) echo -e "\nFilename and label shortend to $FULL_LEN chars" fi filename="${filename//[^[:alnum:]]/-}" filename=$(echo $filename | tr -s -) filename="${filename}-${myuuid}" filename=${filename,,} filename=`sed 's/--/-/g' <<< $filename` [ $input == "i" ] && filename="index-${filename}" CONTEXT_DIR="${BASH_SOURCE%/*}" if [[ ! -d "$CONTEXT_DIR" ]]; then CONTEXT_DIR="$PWD"; fi . "$CONTEXT_DIR/templates/topic-templates.txt" case $input in t) write_stub "${task}" ;; i) write_stub "${index}" ;; r) write_stub "${reference}" ;; g) write_stub "${topic}" ;; f) write_stub "${include}" ;; *) echo -e "$input not valid" ;; esac