dotfiles

my dotfiles.
Log | Files | Refs | README | LICENSE

add_entry.sh (835B)


      1 #!/bin/sh
      2 
      3 english_word=""
      4 spanish_word=""
      5 
      6 OPTS="he:s:"
      7 LONGOPTS="help,english:,spanish:"
      8 
      9 parsed=$(getopt --options=$OPTS --longoptions=$LONGOPTS -- "$@")
     10 eval set -- "${parsed[@]}"
     11 
     12 while true; do
     13   case "$1" in
     14     -e|--english)
     15       english_word="$2"
     16       shift;;
     17 
     18     -s|--spanish)
     19       spanish_word="$2"
     20       shift;;
     21 
     22     --) # end of arguments
     23       shift
     24       break
     25       ;;
     26 
     27     *)
     28       printf '%sn' "Error while parsing CLI options" 1>&2
     29       ;;
     30   esac
     31 
     32   shift
     33 done
     34 
     35 if [ "$english_word" == "" ]; then
     36   echo "english word:"
     37   read english_word
     38 fi
     39 if [ "$spanish_word" == "" ]; then
     40   echo "spanish word:"
     41   read spanish_word
     42 fi
     43 
     44 psql spanish-dictionary -c "INSERT INTO dictionary (word_english, word_spanish, successes, next_appearance) VALUES ('$english_word', '$spanish_word', 0, '$(date --iso-8601=seconds)');"