Skip to content

Instantly share code, notes, and snippets.

@benwei
Created November 27, 2012 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benwei/4153486 to your computer and use it in GitHub Desktop.
Save benwei/4153486 to your computer and use it in GitHub Desktop.
yd script is a simple wrapper while cache read word for ydict
#!/bin/sh
YD_HIST_DIR="${HOME}/.ydict_history"
mkdir -p "$YD_HIST_DIR/_relation/"
echo "$@" >> "${YD_HIST_DIR}"/_words.txt
WordCacheFile="${YD_HIST_DIR}"/"$@".txt
WordRelationFile="${YD_HIST_DIR}"/_relation/"$@".txt
if [ ! -f "$WordCacheFile" ]; then
ydict -u -w "$@" | sed -e "s/'/'/g" -e "s/\(.\[36m\)[ ]*/\1 /g" > "$WordCacheFile"
fi
cat "$WordCacheFile"
wc -l "$WordCacheFile" | ( read size file ;
if [ $size -eq 2 ]; then
echo "remove $file with 2 line "
rm "$file"
fi
)
if [ -f "$WordRelationFile" ]; then
echo "=== Relation ==="
cat "$WordRelationFile"
fi
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment