# HG changeset patch # User Igor Chubin # Date 1267803360 -7200 # Node ID 0d44e794175b9258b467df5b17da8bb2f42ad4b9 # Parent c703b8898696cc1feb5411ac69881b0505b04a98 Добавился файл learn-words.sh, простой скрипт для запоминания новых слов с пометками diff -r c703b8898696 -r 0d44e794175b learn-words.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/learn-words.sh Fri Mar 05 17:36:00 2010 +0200 @@ -0,0 +1,96 @@ +#!/bin/bash + +LANGUAGE=en +N=50 +REVERSED=NO + +show_usage() +{ + cat< /dev/stderr + +Usage: + $0 [ -l LANG ] [ -r ] [ N ] + +Help to learn N (number) previously marked words from LANG language. + +Options: + -r reversed mode (show the note first; the word second) + +By default: + + LANG = $LANGUAGE + N = $N + REVERSED = $REVERSED + +USAGE +} + +if [ "$1" = -l ] +then + if [ -n "$2" ] + then + LANGUAGE="$2" + shift 2 + else + echo "Error: Please, specify LANGUAGE (en, de, ru,...) after -l or don't use -l switch" > /dev/stderr + show_usage + exit 1 + fi +fi + +if [ "$1" = -r ] +then + REVERSED="YES" + shift +fi + +if [ -n "$1" ] +then + if echo "$1" | grep -qx '[0-9]\+' + then + N="$1" + else + echo "Error: Number of words N should be numeric. " > /dev/stderr + echo " Please provide a number or don't specify N at all " > /dev/stderr + show_usage + exit 1 + fi +fi + +notes_file=~/".new-words/notes-$LANGUAGE".txt +if [ -e $notes_file ] +then + true + number="`wc -l $notes_file | awk '{print $1}'`" + if [ "$number" -lt "$N" ] + then + echo "Warning: The notes file for the language is too short. Truncating N to $number" > /dev/stderr + N="$number" + fi + while true + do + main_script="$$" + tail -n $((1+$RANDOM%$N)) $notes_file | head -1 | while read word note + do + trap "kill -1 $main_script; kill -1 $$" 2 + if [ "$REVERSED" = "NO" ] + then + echo $word + read < /dev/tty + echo $note + read < /dev/tty + clear + else + echo $note + read < /dev/tty + echo $word + read < /dev/tty + clear + fi + done + done +else + echo "Error: Uknown language '$LANGUAGE'" > /dev/stderr + echo " File $notes_file not found" > /dev/stderr + exit 1 +fi