new-words

diff learn-words.sh @ 47:d708e2c1bad8

compressed wordlist support
author Igor Chubin <igor@chub.in>
date Mon Feb 07 21:21:17 2011 +0200 (2011-02-07)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/learn-words.sh	Mon Feb 07 21:21:17 2011 +0200
     1.3 @@ -0,0 +1,96 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +LANGUAGE=en
     1.7 +N=50
     1.8 +REVERSED=NO
     1.9 +
    1.10 +show_usage()
    1.11 +{
    1.12 +    cat<<USAGE > /dev/stderr
    1.13 +
    1.14 +Usage:
    1.15 +    $0 [ -l LANG ] [ -r ] [ N ]
    1.16 +
    1.17 +Help to learn N (number) previously marked words from LANG language.
    1.18 +
    1.19 +Options:
    1.20 +    -r  reversed mode (show the note first; the word second)
    1.21 +
    1.22 +By default:
    1.23 +
    1.24 +    LANG     =  $LANGUAGE
    1.25 +    N        =  $N
    1.26 +    REVERSED =  $REVERSED
    1.27 +
    1.28 +USAGE
    1.29 +}
    1.30 +
    1.31 +if [ "$1" = -l ]
    1.32 +then  
    1.33 +    if [ -n "$2" ]
    1.34 +    then
    1.35 +        LANGUAGE="$2"
    1.36 +        shift 2
    1.37 +    else 
    1.38 +        echo "Error: Please, specify LANGUAGE (en, de, ru,...) after -l or don't use -l switch" > /dev/stderr
    1.39 +        show_usage
    1.40 +        exit 1
    1.41 +    fi
    1.42 +fi
    1.43 +
    1.44 +if [ "$1" = -r ]
    1.45 +then  
    1.46 +    REVERSED="YES"
    1.47 +    shift
    1.48 +fi
    1.49 +
    1.50 +if [ -n "$1" ]
    1.51 +then
    1.52 +    if echo "$1" | grep -qx '[0-9]\+'
    1.53 +    then
    1.54 +        N="$1"
    1.55 +    else
    1.56 +        echo "Error: Number of words N should be numeric. " > /dev/stderr
    1.57 +        echo "       Please provide a number or don't specify N at all " > /dev/stderr
    1.58 +        show_usage
    1.59 +        exit 1
    1.60 +    fi
    1.61 +fi
    1.62 +
    1.63 +notes_file=~/".new-words/notes-$LANGUAGE".txt
    1.64 +if [ -e $notes_file ]
    1.65 +then
    1.66 +    true
    1.67 +    number="`wc -l $notes_file | awk '{print $1}'`"
    1.68 +    if [ "$number" -lt "$N" ]
    1.69 +    then
    1.70 +        echo "Warning: The notes file for the language is too short. Truncating N to $number" > /dev/stderr
    1.71 +        N="$number"
    1.72 +    fi
    1.73 +    while true
    1.74 +    do
    1.75 +        main_script="$$"
    1.76 +        tail -n $((1+$RANDOM%$N)) $notes_file | head -1 | while read word note
    1.77 +        do
    1.78 +            trap "kill -1 $main_script; kill -1 $$" 2
    1.79 +            if [ "$REVERSED" = "NO" ]
    1.80 +            then 
    1.81 +                echo $word
    1.82 +                read < /dev/tty
    1.83 +                echo $note
    1.84 +                read < /dev/tty
    1.85 +                clear
    1.86 +            else
    1.87 +                echo $note
    1.88 +                read < /dev/tty
    1.89 +                echo $word
    1.90 +                read < /dev/tty
    1.91 +                clear
    1.92 +            fi
    1.93 +        done
    1.94 +    done
    1.95 +else
    1.96 +    echo "Error: Uknown language '$LANGUAGE'" > /dev/stderr
    1.97 +    echo "       File $notes_file not found" > /dev/stderr
    1.98 +    exit 1
    1.99 +fi