igor@4: #!/bin/bash igor@4: igor@4: LANGUAGE=en igor@4: N=50 igor@4: REVERSED=NO igor@4: igor@4: show_usage() igor@4: { igor@4: cat< /dev/stderr igor@4: igor@4: Usage: igor@4: $0 [ -l LANG ] [ -r ] [ N ] igor@4: igor@4: Help to learn N (number) previously marked words from LANG language. igor@4: igor@4: Options: igor@4: -r reversed mode (show the note first; the word second) igor@4: igor@4: By default: igor@4: igor@4: LANG = $LANGUAGE igor@4: N = $N igor@4: REVERSED = $REVERSED igor@4: igor@4: USAGE igor@4: } igor@4: igor@4: if [ "$1" = -l ] igor@4: then igor@4: if [ -n "$2" ] igor@4: then igor@4: LANGUAGE="$2" igor@4: shift 2 igor@4: else igor@4: echo "Error: Please, specify LANGUAGE (en, de, ru,...) after -l or don't use -l switch" > /dev/stderr igor@4: show_usage igor@4: exit 1 igor@4: fi igor@4: fi igor@4: igor@4: if [ "$1" = -r ] igor@4: then igor@4: REVERSED="YES" igor@4: shift igor@4: fi igor@4: igor@4: if [ -n "$1" ] igor@4: then igor@4: if echo "$1" | grep -qx '[0-9]\+' igor@4: then igor@4: N="$1" igor@4: else igor@4: echo "Error: Number of words N should be numeric. " > /dev/stderr igor@4: echo " Please provide a number or don't specify N at all " > /dev/stderr igor@4: show_usage igor@4: exit 1 igor@4: fi igor@4: fi igor@4: igor@4: notes_file=~/".new-words/notes-$LANGUAGE".txt igor@4: if [ -e $notes_file ] igor@4: then igor@4: true igor@4: number="`wc -l $notes_file | awk '{print $1}'`" igor@4: if [ "$number" -lt "$N" ] igor@4: then igor@4: echo "Warning: The notes file for the language is too short. Truncating N to $number" > /dev/stderr igor@4: N="$number" igor@4: fi igor@4: while true igor@4: do igor@4: main_script="$$" igor@4: tail -n $((1+$RANDOM%$N)) $notes_file | head -1 | while read word note igor@4: do igor@4: trap "kill -1 $main_script; kill -1 $$" 2 igor@4: if [ "$REVERSED" = "NO" ] igor@4: then igor@4: echo $word igor@4: read < /dev/tty igor@4: echo $note igor@4: read < /dev/tty igor@4: clear igor@4: else igor@4: echo $note igor@4: read < /dev/tty igor@4: echo $word igor@4: read < /dev/tty igor@4: clear igor@4: fi igor@4: done igor@4: done igor@4: else igor@4: echo "Error: Uknown language '$LANGUAGE'" > /dev/stderr igor@4: echo " File $notes_file not found" > /dev/stderr igor@4: exit 1 igor@4: fi