Added the limit option
This commit is contained in:
parent
0cc9f2e659
commit
fdb5f37f59
10
README.md
10
README.md
|
@ -1,8 +1,10 @@
|
|||
# pronounce.sh
|
||||
Plays/downloads the Wiktionary pronounciation of a word.
|
||||
*Usage:* "**pronounce.sh WORD [-po filename]**"
|
||||
Plays/downloads the Wiktionary pronunciation of a word.
|
||||
*Usage:* "**pronounce.sh WORD [limit -po filename]**"
|
||||
|
||||
If you use the "**-p**" option, then isntead of saving the pronounciation, it will be played.
|
||||
If you use the limit option, then write a number-- then only that number of pronunciations (if available) will be played.
|
||||
|
||||
If you use the "**-p**" option, then instead of saving the pronunciation, it will be played.
|
||||
|
||||
If you use the "**-o**" option, then it will be saved to the specified filename.
|
||||
|
||||
|
@ -12,6 +14,6 @@ Oh, and the options *must* come after the word.
|
|||
|
||||
There's a bloody eel in my hovercraft, dammit! How do I say hovercraft?
|
||||
|
||||
```$ pronounce.sh hovercraft -p```
|
||||
```$ pronounce.sh hovercraft 1 -p```
|
||||
|
||||
Only tested on OpenBSD's ksh, but it should work on bash and other modern shells.
|
||||
|
|
40
pronounce.sh
40
pronounce.sh
|
@ -8,7 +8,20 @@
|
|||
player="play"
|
||||
|
||||
WORD=$1
|
||||
OPTIONTWO=$2
|
||||
INDEX=0
|
||||
if echo "$2" | grep "\-." > /dev/null
|
||||
then
|
||||
OPTION="$2"
|
||||
OUTPUT="$3"
|
||||
elif echo "$2" | grep ".$" > /dev/null
|
||||
then
|
||||
LIMIT="$2"
|
||||
if [ -n "$3" ]
|
||||
then
|
||||
OPTION="$3"
|
||||
OUTPUT="$4"
|
||||
fi
|
||||
fi
|
||||
|
||||
wd_pg=/tmp/wt_wd_pg
|
||||
fl_pg=/tmp/wt_fl_pg
|
||||
|
@ -32,26 +45,35 @@ do
|
|||
|
||||
FL_URL=$(echo "https:$(cat $fl_url)")
|
||||
|
||||
if [ -n "$OPTIONTWO" ]
|
||||
if [ -n "$OPTION" ]
|
||||
then
|
||||
case "$OPTIONTWO" in
|
||||
case "$OPTION" in
|
||||
-p)
|
||||
ftp -Vo $fl $FL_URL > /dev/null
|
||||
$player $fl
|
||||
;;
|
||||
-o)
|
||||
ftp -Vo "$3" $FL_URL > /dev/null
|
||||
ftp -Vo "$OUTPUT" $FL_URL > /dev/null
|
||||
;;
|
||||
-po)
|
||||
ftp -Vo "$3" $FL_URL > /dev/null
|
||||
$player "$3"
|
||||
ftp -Vo "$OUTPUT" $FL_URL > /dev/null
|
||||
$player "$OUTPUT"
|
||||
;;
|
||||
esac
|
||||
elif [ -z "$OPTIONTWO" ]
|
||||
elif [ -z "$OPTION" ]
|
||||
then
|
||||
ftp -V $FL_URL > dev/null
|
||||
ftp -V $FL_URL > /dev/null
|
||||
fi
|
||||
if [ -n "$LIMIT" ]
|
||||
then
|
||||
INDEX=$((INDEX+1))
|
||||
if [ $LIMIT -eq $INDEX ]
|
||||
then
|
||||
rm $wd_pg $fl_pg $fl_pg_url $fl_url $fl
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Cleanup
|
||||
rm $wd_pg $fl_pg $fl_pg_url $fl_url $fl
|
||||
rm $wd_pg $fl_pg $fl_pg_url $fl_url $fl 2> /dev/null
|
||||
|
|
Reference in New Issue