new-words
annotate learn-words.sh @ 56:6d6655d4cab6
new-words.pl stub removed
author | Igor Chubin <igor@chub.in> |
---|---|
date | Thu Nov 03 16:01:53 2011 +0100 (2011-11-03) |
parents | |
children |
rev | line source |
---|---|
igor@4 | 1 #!/bin/bash |
igor@4 | 2 |
igor@4 | 3 LANGUAGE=en |
igor@4 | 4 N=50 |
igor@4 | 5 REVERSED=NO |
igor@4 | 6 |
igor@4 | 7 show_usage() |
igor@4 | 8 { |
igor@4 | 9 cat<<USAGE > /dev/stderr |
igor@4 | 10 |
igor@4 | 11 Usage: |
igor@4 | 12 $0 [ -l LANG ] [ -r ] [ N ] |
igor@4 | 13 |
igor@4 | 14 Help to learn N (number) previously marked words from LANG language. |
igor@4 | 15 |
igor@4 | 16 Options: |
igor@4 | 17 -r reversed mode (show the note first; the word second) |
igor@4 | 18 |
igor@4 | 19 By default: |
igor@4 | 20 |
igor@4 | 21 LANG = $LANGUAGE |
igor@4 | 22 N = $N |
igor@4 | 23 REVERSED = $REVERSED |
igor@4 | 24 |
igor@4 | 25 USAGE |
igor@4 | 26 } |
igor@4 | 27 |
igor@4 | 28 if [ "$1" = -l ] |
igor@4 | 29 then |
igor@4 | 30 if [ -n "$2" ] |
igor@4 | 31 then |
igor@4 | 32 LANGUAGE="$2" |
igor@4 | 33 shift 2 |
igor@4 | 34 else |
igor@4 | 35 echo "Error: Please, specify LANGUAGE (en, de, ru,...) after -l or don't use -l switch" > /dev/stderr |
igor@4 | 36 show_usage |
igor@4 | 37 exit 1 |
igor@4 | 38 fi |
igor@4 | 39 fi |
igor@4 | 40 |
igor@4 | 41 if [ "$1" = -r ] |
igor@4 | 42 then |
igor@4 | 43 REVERSED="YES" |
igor@4 | 44 shift |
igor@4 | 45 fi |
igor@4 | 46 |
igor@4 | 47 if [ -n "$1" ] |
igor@4 | 48 then |
igor@4 | 49 if echo "$1" | grep -qx '[0-9]\+' |
igor@4 | 50 then |
igor@4 | 51 N="$1" |
igor@4 | 52 else |
igor@4 | 53 echo "Error: Number of words N should be numeric. " > /dev/stderr |
igor@4 | 54 echo " Please provide a number or don't specify N at all " > /dev/stderr |
igor@4 | 55 show_usage |
igor@4 | 56 exit 1 |
igor@4 | 57 fi |
igor@4 | 58 fi |
igor@4 | 59 |
igor@4 | 60 notes_file=~/".new-words/notes-$LANGUAGE".txt |
igor@4 | 61 if [ -e $notes_file ] |
igor@4 | 62 then |
igor@4 | 63 true |
igor@4 | 64 number="`wc -l $notes_file | awk '{print $1}'`" |
igor@4 | 65 if [ "$number" -lt "$N" ] |
igor@4 | 66 then |
igor@4 | 67 echo "Warning: The notes file for the language is too short. Truncating N to $number" > /dev/stderr |
igor@4 | 68 N="$number" |
igor@4 | 69 fi |
igor@4 | 70 while true |
igor@4 | 71 do |
igor@4 | 72 main_script="$$" |
igor@4 | 73 tail -n $((1+$RANDOM%$N)) $notes_file | head -1 | while read word note |
igor@4 | 74 do |
igor@4 | 75 trap "kill -1 $main_script; kill -1 $$" 2 |
igor@4 | 76 if [ "$REVERSED" = "NO" ] |
igor@4 | 77 then |
igor@4 | 78 echo $word |
igor@4 | 79 read < /dev/tty |
igor@4 | 80 echo $note |
igor@4 | 81 read < /dev/tty |
igor@4 | 82 clear |
igor@4 | 83 else |
igor@4 | 84 echo $note |
igor@4 | 85 read < /dev/tty |
igor@4 | 86 echo $word |
igor@4 | 87 read < /dev/tty |
igor@4 | 88 clear |
igor@4 | 89 fi |
igor@4 | 90 done |
igor@4 | 91 done |
igor@4 | 92 else |
igor@4 | 93 echo "Error: Uknown language '$LANGUAGE'" > /dev/stderr |
igor@4 | 94 echo " File $notes_file not found" > /dev/stderr |
igor@4 | 95 exit 1 |
igor@4 | 96 fi |