new-words

diff new-words.sh @ 21:190d4ac6b07c

-m and -n switches
author Igor Chubin <igor@chub.in>
date Thu May 06 21:05:20 2010 +0300 (2010-05-06)
parents 23f949c03f95
children 46e987f4636d
line diff
     1.1 --- a/new-words.sh	Wed Apr 28 21:00:38 2010 +0300
     1.2 +++ b/new-words.sh	Thu May 06 21:05:20 2010 +0300
     1.3 @@ -13,6 +13,8 @@
     1.4      -h          print this screen
     1.5      -k          put higher words that are similar to the known words (only for English)
     1.6      -l lang     override language settings
     1.7 +    -n          non-interactive mode (don't run vi)
     1.8 +    -m          don't add marks (and don't save marks added by user)
     1.9      -s          show the text statistics (percentage of known words and so on) and exit
    1.10  
    1.11  The language of the text can be specified also
    1.12 @@ -37,6 +39,9 @@
    1.13  export ORIGINAL_TEXT=`mktemp /tmp/new-words-XXXXXXXXXX-orig`
    1.14  editor=${EDITOR:-vim}
    1.15  
    1.16 +#----------------------------------------------------
    1.17 +# command line options processing
    1.18 +
    1.19  LANGUAGE=en
    1.20  my_name="`echo $0 | sed s@.*/@@ | sed s/-.*// `"
    1.21  if echo "$1" | grep -q http://...wikipedia.org/wiki/
    1.22 @@ -67,6 +72,22 @@
    1.23      shift
    1.24  fi
    1.25  
    1.26 +DONT_ADD_MARKS=NO
    1.27 +if [ "$1" = "-m" ]
    1.28 +then
    1.29 +    DONT_ADD_MARKS=YES
    1.30 +    shift
    1.31 +fi
    1.32 +
    1.33 +NON_INTERACTIVE_MODE=NO
    1.34 +if [ "$1" = "-n" ]
    1.35 +then
    1.36 +    NON_INTERACTIVE_MODE=YES
    1.37 +    shift
    1.38 +fi
    1.39 +
    1.40 +#----------------------------------------------------
    1.41 +
    1.42  get_words()
    1.43  {
    1.44  tr ' ' '\n' | sed 's/--/ /g' \
    1.45 @@ -341,7 +362,7 @@
    1.46          }
    1.47      }
    1.48  }
    1.49 -if (open(NOTES, $ENV{NOTES_FILE})) {
    1.50 +if (($ENV{DONT_ADD_MARKS} ne "YES") and open(NOTES, $ENV{NOTES_FILE})) {
    1.51      @lines=<NOTES>;
    1.52      close(NOTES);
    1.53  
    1.54 @@ -365,6 +386,7 @@
    1.55  PERL_SCRIPT
    1.56      [ -e "$NOTES_FILE" ] || touch "$NOTES_FILE"
    1.57      export NOTES_FILE
    1.58 +    export DONT_ADD_MARKS
    1.59      perl $PERL_SCRIPT_TEMP_NAME "$1"
    1.60      rm $PERL_SCRIPT_TEMP_NAME
    1.61  }
    1.62 @@ -395,8 +417,11 @@
    1.63  if [ "$STAT_ONLY" = "YES" ]
    1.64  then
    1.65      cat "$TEMP1"
    1.66 +elif [ "$NON_INTERACTIVE_MODE" = "YES" ]
    1.67 +then
    1.68 +    cat "$TEMP1"
    1.69  else
    1.70 -    add_marks "$TEMP2"
    1.71 +    [ "$DONT_ADD_MARKS" = "YES" ] || add_marks "$TEMP2"
    1.72      if [ "$editor" = vim ]
    1.73      then
    1.74          vim -c 'set keywordprg='"$LANGUAGE" -c 'set iskeyword=@,48-57,/,.,-,_,+,,,#,$,%,~,=' "$TEMP2" < /dev/tty > /dev/tty