Faire des qcm simplement - retour accueil
git clone git://bebou.netlib.re/qcm
Log | Files | Refs | README |
writeqcm.sh (1904B)
1 #! /bin/sh 2 3 res=$(mktemp) 4 tmp=$(mktemp) 5 6 writequestion() { 7 echo "question: \"$q\"" >> $1 8 echo "type: $t" >> $1 9 [ -n "$o" ] && echo "options: $o" >> $1 10 [ -n "$c" ] && echo "choix: $c" >> $1 11 echo "unique: $r" >> $1 12 echo "demander\n" >> $1 13 } 14 15 confirmquestion() { 16 echo "La question : \n" >&2 17 cat $tmp 1>&2 18 conf=$(echo "oui\nnon" | gum choose --header="Cette question est correcte ?") 19 } 20 21 addquestion() { 22 echo "Le questionnaire complet : \n" >&2 23 cat $res 1>&2 24 fin=$(echo "oui\nnon" | gum choose --header="Ajouter une question ?") 25 } 26 27 gatherquestion() { 28 q=$(echo "$q" | 29 gum write \ 30 --header="Tapez votre question" \ 31 --header.foreground="#875fff" \ 32 --placeholder="De quelle couleur est le cheval blanc d'Henri IV") 33 t=$(echo "qcm\nvote\nregex\nouverte" | 34 gum choose \ 35 --header="Quel type de question ?" \ 36 --selected=$t) 37 if [ "$t" = "qcm" ];then 38 c=$(echo "multiple\nunique" | 39 gum choose \ 40 --header="Choix multiple ou unique" \ 41 --selected=$c) 42 o=$(echo "$o" | 43 tr '~' '\n' | 44 gum write \ 45 --header="Les options de réponses, une par ligne" \ 46 --header.foreground="#875fff" \ 47 --placeholder="Réponse A" | 48 grep -v "^$" | paste -s -d '~' - | sed -E 's/(~ *)+$//') 49 fi 50 [ "$t" = "regex" ] \ 51 && o=$(echo "$o" | 52 gum input \ 53 --header="La regex" \ 54 --header.foreground="#875fff" \ 55 --placeholder="Par ex pour des années -?[0-9]+") 56 r=$(echo "oui\nnon" | 57 gum choose \ 58 --header="Une seule réponse autorisée ?" \ 59 --selected=$r) 60 } 61 62 command -V gum >&2 /dev/null || { echo "Il faut gum";exit 1; } 63 64 while [ "$fin" != "non" ];do 65 conf=;q=;t=;c=;o=;r=; 66 while [ "$conf" != "oui" ];do 67 cat /dev/null > $tmp 68 clear >&2 69 gatherquestion 70 writequestion $tmp 71 clear >&2 72 confirmquestion 73 done 74 writequestion $res 75 clear >&2 76 addquestion 77 done 78 79 [ -n "$1" ] && cat $res > $1 || cat $res 80