Debian Codegraph @

fortune-zh

raw
1 #!/bin/sh
2 # fortune-zh
3 set -e
4
5 FORTUNE="/usr/games/fortune"
6 [ -x $FORTUNE ] || ( echo "E: Please install package 'fortune-mod'."; false )
7
8 # The old version (1.*) of fortune-zh contains only tang300 and song100.
9 # Note, $\sum_{i} P_i = 1$, i.e. all the possibilities must sum to 1.
10 DICT="7% tang300 2% song100 91% chinese"
11
12 # check LANG
13 if [ ! -z $LC_ALL ]; then
14 LANG="$LC_ALL"
15 fi
16
17 # output according to LANG
18 case "$LANG" in
19 "zh_CN.GB2312")
20 LANG=zh_CN.UTF8 $FORTUNE $DICT | iconv -c -f utf8 -t gbk
21 ;;
22 "zh_TW.Big5")
23 LANG=zh_TW.UTF8 $FORTUNE $DICT | iconv -c -f utf8 -t big5
24 ;;
25 *)
26 if [ ! -z "$FORTUNEZH_NOCOLOR" ]; then
27 $FORTUNE $DICT | sed -r "s/\x1b\[([0-9]{1,2}(;[0-9]{1,2})?)?m//g"
28 else
29 $FORTUNE $DICT
30 fi
31 ;;
32 esac