#!/usr/bin/env bash _link="https://tildegit.org/konomo/gem-pd" readonly _link _runthru=1 # whether or not a random selection of sentences should be taken readonly _runthru _sentences=6 # how many sentences are displayed if [[ -z "$QUERY_STRING" ]]; then printf "10 Please enter your name. You may add ; and your preferred pronoun\r\n" fi name=$QUERY_STRING pronoun="" setnumber=999 if [[ "${name}" == *"%3B"* ]]; then pronoun="${name#*%3B}" name=$(echo -n "${name}" | sed 's/%3B.*//') elif [[ "${name}" == *";"* ]]; then # This shouldn't happen, but I have seen it with Xenia on Android pronoun="${name#*;}" name=$(echo -n "${name}" | sed 's/;.*//') fi printf "20 text/gemini\r\n" printf "# Pronoun Dressing Room for %s" "$name" while read sentence; do sentences+=("${sentence}"); done < sentences if [[ "${_runthru}" -eq 1 ]]; then prevs=() sentarr=() for (( i = 0; i < ${_sentences}; i++ )); do while ran=$(( RANDOM % ${#sentences[@]} + 0)) [[ "${prevs[@]}" =~ "${ran}" ]] # generate new random numbers until it isn't already in array do true; done prevs+=(${ran}) sentarr+=("${sentences[${ran}]}") done prevs=() # prevs is no longer needed sentences=() # empty original array sentences=("${sentarr[@]}") fi pr_sub=( $(tail -n +2 pronouns.csv | cut -d ',' -f1) ) pr_obj=( $(tail -n +2 pronouns.csv | cut -d ',' -f2) ) pr_psd=( $(tail -n +2 pronouns.csv | cut -d ',' -f3) ) pr_pos=( $(tail -n +2 pronouns.csv | cut -d ',' -f4) ) pr_ref=( $(tail -n +2 pronouns.csv | cut -d ',' -f5) ) pr_plr=( $(tail -n +2 pronouns.csv | cut -d ',' -f6) ) cnt=0 if [[ "${pronoun}" != "" ]]; then # looks through the loaded pronouns to see if the preferred pronoun # that was (optionally) entered is available. for i in "${pr_sub[@]}"; do if [[ "${i}" == "${pronoun}" ]]; then setnumber=$cnt fi ((cnt++)) done # if the pronoun entered is known, # then say so if [[ "${pr_sub[@]}" =~ "${pronoun}" ]]; then printf " (%s)\n" "${pronoun}" else printf " (unknown pronoun)\n" fi else printf "\n" fi cnt=0 for i in "${pr_sub[@]}"; do if [[ "${setnumber}" != 999 ]]; then if [[ "${setnumber}" != "${cnt}" ]]; then ((cnt++)) continue fi fi if [[ "${setnumber}" == 999 ]]; then printf "%s:\n---\n" "$i" fi for j in "${sentences[@]}"; do cursent="${j}" if [[ "${pr_plr[${cnt}]}" -eq 1 ]]; then cursent="${cursent//MSHAS/have}" fi cursent="${cursent//MSHAS/has}" cursent="${cursent//NAME/${name}}" cursent="${cursent//SUBJECTIVE/"${pr_sub[${cnt}]}"}" cursent="${cursent//OBJECTIVE/"${pr_obj[${cnt}]}"}" cursent="${cursent//POSSESSIVEDT/"${pr_psd[${cnt}]}"}" cursent="${cursent//POSSESSIVE/"${pr_pos[${cnt}]}"}" cursent="${cursent//REFLEXIVE/"${pr_ref[${cnt}]}"}" printf "* %s\n" "${cursent^}" done printf "\n" ((cnt++)) done printf "=> ${_link} Check out the source code\n" ownname=$(basename "$0") if [[ "${ownname}" == "index.gmi" ]]; then # if script is in its own dir printf "=> ../index.gmi Back" # then go to parent dir else printf "=> index.gmi Back" # else go to regular index fi exit