1.点击这里下载sunpinyin的词典文件,解压后覆盖~/.sunpinyin/userdict文件即可;
2.保存下面的脚本内容到 sunpinyin_accelerate.sh 文件中,给与该脚本可执行权限,并移动该脚本到你认为合适的位置;
1 #!/bin/bash 2 # 本脚本主要功能:将 userdict 文件缓存到 RAM 中,并每隔一段时间进行备份; 3 # 字典文件可从 http://hslinuxextra.googlecode.com/files/sunpinyin-userdict.7z 下载 4 # 初次运行脚本前,解压 sunpinyin-userdict.7z 里面的 userdict,并覆盖到 ~/.sunpinyin/userdict 。 5 # 以后将该脚本加入到本用户的corntab中,时间周期自定,以便定期备份和开机初始化。 6 7 userdict_link="$HOME/.sunpinyin/userdict" 8 userdict_bak="$HOME/.sunpinyin/userdict_bak" 9 userdict_ram="/dev/shm/userdict" 10 11 # 环境检测 12 [ $UID -eq 0 ] && echo "Please run as ordinary user,NOT root!!!" && exit 1 13 ! ls ${userdict_link} &> /dev/null && [ ! -f ${userdict_bak} ] && echo "There is no userdict - 1 !!!" && exit 1 14 15 # 初始化 16 # check userdict_link 17 if [ "$(readlink -qsn ${userdict_link})" == "${userdict_ram}" ]; then 18 : 19 else 20 if ! ls ${userdict_link} &> /dev/null; then 21 ln -s ${userdict_ram} ${userdict_link} 22 elif [ -L ${userdict_link} ]; then 23 unlink ${userdict_link} 24 ln -s ${userdict_ram} ${userdict_link} 25 else 26 mv ${userdict_link} ${userdict_bak} 27 ln -s ${userdict_ram} ${userdict_link} 28 fi 29 fi 30 31 if ls ${userdict_link} &> /dev/null && [ "$(readlink -qsn ${userdict_link})" == "${userdict_ram}" ]; then 32 : 33 else 34 echo "Link Fail !!!" 35 exit 1 36 fi 37 38 39 # for userdict_bak 40 if [ "$(du ${userdict_bak} 2> /dev/null | cut -f 1)" -ne 0 ]; then 41 : 42 else 43 echo "Bak Fail !!! " 44 exit 1 45 fi 46 47 # for userdict_ram 48 if [ "$(du ${userdict_ram} 2> /dev/null | cut -f 1)" -ne 0 ]; then 49 : 50 else 51 rm -f ${userdict_ram} || exit 3 52 cp ${userdict_bak} ${userdict_ram} 53 chmod u+w ${userdict_ram} 54 fi 55 56 if [ ! -w ${userdict_ram} ]; then 57 echo "Ram Fail !!!" 58 exit 1 59 fi 60 61 62 # backup userdict for storage data 63 cp -u ${userdict_ram} ${userdict_bak} 64 65 exit 0
3.以root用户身份打开 /etc/rc.local 文件,在 exit 0 之前插入下面这条命令,以便开机进行初始化:
sudo -u 你的普通用户名 -i 你自定义的存放目录/sunpinyin_accelerate.sh
4.加入 corntab周期性执行,以便备份词典新添加的词句:
crontab -e # 添加下面的内容: # 我这里备份周期为15分钟,你可以自定义 */15 * * * * 你的自定义存放目录/sunpinyin_accelerate.sh
时间: 2024-10-15 12:01:35