Created
July 12, 2011 09:45
-
-
Save s5unty/1077695 to your computer and use it in GitHub Desktop.
将标准日本语单词文件中的随机一行输出到屏幕 osd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 添加 cron 调度时,在命令前必须添加 DISPLAY=:0,否则 osd 不能正常显示,例如 | |
# | |
# # 每 5 分钟在第 15 课(616行开始)和第 16 课(707行结束)的单词中随机挑选一个显示: | |
# */5 * * * * env DISPLAY=:0 /sun/desktop/rword /sun/archive/japanese_word.txt 616 707 & | |
# | |
file=$1 # 字典文件绝对路径 | |
from=$2 # 随机输出行数范围的最小值 | |
till=$3 # 随机输出行数范围的最大值 | |
rand(){ # urandom 比 $RANDOM 的随机效果好,而且这种方法不依赖 bash ($RANDOM 在 dash 中无效) | |
head -c4 /dev/urandom | od -tu4 | awk 'NR=1{print $2}' | |
} | |
if [ -z ${file} ]; then | |
exit 1 | |
fi | |
if [ -z ${from} ]; then | |
from=0 | |
fi | |
if [ -z ${till} || ${till} -lt ${from} ]; then | |
till=$((`wc -l $file | cut -d' ' -f1`)) | |
fi | |
# 在字典里随机找一个单词 | |
while true; do | |
line=$(($(rand) % $(($till-$from+1)) + $from)) | |
test=`sed -n "${line}p" $file` | |
if ! echo ${test} | grep -e "^|[^|]\+|[^|]\+|$" 2>&1 > /dev/null; then | |
continue | |
elif echo ${test} | grep -e "|\s\+|" 2>&1 > /dev/null; then | |
continue | |
else | |
break | |
fi | |
done | |
# 格式化一下 | |
ret=`echo ${test} | sed -s "s/\(\s\)*|//g"` | |
# 输出到 osd | |
echo ${ret} | aosd_cat -t 2 -e 0 -u 30000 -f 7000 -o 8000 -p 1 -x -3 -y 3 -b 255 -B yellow -R black |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment