因为sunpinyin词库一大就会卡,因此需要自己添加一个脚本给sunpinyin加速。

加速的原理就是把词库添加到内存,现在内存都这么大,根本不在乎这么几兆,当然输入体验更重要啦~

首先先建一个脚本实现把词库放到内存中的功能,脚本就取名为sunpinyin_speed_up吧。

#!/bin/sh

# Capture the exit signal, make sure it is the FIRST uncommented line.
trap "do_exit" SIGHUP SIGINT SIGQUIT SIGTERM SUN_DIR="/home/xuzhenan/.sunpinyin"
SHM_USERDICT="/dev/shm/sunpinyin_userdict.sh0" # Backup the userdict and restore all changes made by this script on exit.
do_exit() {
cp -f "${SHM_USERDICT}" "${SUN_DIR}/userdict.real"
rm -f "${SHM_USERDICT}"
mv -f "${SUN_DIR}/userdict.real" "${SUN_DIR}/userdict"
#notify-send 'Pinyin dict' 'done'
exit
} # Work around for abnormal quit.
if [ -e "${SUN_DIR}/userdict.real" ]
then
rm -f "${SHM_USERDICT}"
mv -f "${SUN_DIR}/userdict.real" "${SUN_DIR}/userdict"
fi # Rename the real userdict, copy it to RAM and make a symblic link back.
# From now on the modification and query on userdict takes place in RAM.
mv -f "${SUN_DIR}/userdict" "${SUN_DIR}/userdict.real"
cp -f "${SUN_DIR}/userdict.real" "${SHM_USERDICT}"
ln -sf "${SHM_USERDICT}" "${SUN_DIR}/userdict" # Automatically backup the userdict, make sure not losing the modification.
p_count=
while [ true ]
do
p_count=$(($p_count+))
sleep if [ $p_count == ]
then
p_count=
cp -f "${SHM_USERDICT}" "${SUN_DIR}/userdict.real"
fi p_size_shm=$(ls -l "${SHM_USERDICT}" | awk '{print $5}')
p_size_real_t=$(ls -l "${SUN_DIR}/userdict.real" | awk '{print $5}')
p_size_real=$(($p_size_real_t+)) if [ $p_size_shm -ge $p_size_real ]
then
cp -f "${SHM_USERDICT}" "${SUN_DIR}/userdict.real"
fi
done

sunpinyin_speed_up

之后将其设置为开机启动就好了。

因为我们用systemd的方式,所以需要再写一个开机启动的服务放到/etc/systemd/system/中。

[Unit]
Description=Sunpinyin dict cache [Service]
ExecStart=/home/xuzhenan/mysh/sunpinyin_speed_up [Install]
WantedBy=multi-user.target

sunpinyin_speed_up.service

之后运行

sudo systemctl enable sunpinyin_speed_up.service 

将其设置为开机自启动就好了。

最新文章

  1. PHP_$_SERVER_说明详解
  2. Red Black Tree in C
  3. BZOJ3625: [Codeforces Round #250]小朋友和二叉树
  4. HTML5——语音输入
  5. SPSS常用基础操作(1)——变量分组
  6. iis设置Gzip后,无后缀的url无法压缩解决 MVC iis GZIP
  7. Moogoose操作之Schema实现增删查改
  8. OSG绘制几何图形
  9. ubuntu记录
  10. php非递归无限级分类.
  11. ubuntu14.04下编译安装ambari-2.4.2.0
  12. 再起航,我的学习笔记之JavaScript设计模式11(外观模式)
  13. kubernetes系列11—PV和PVC详解
  14. React 实现拖拽功能
  15. Judy Beta Postmortem
  16. 去掉dede织梦position当前位置最后一个箭头的方法
  17. JVM(二)垃圾回收
  18. Linux统计系统文件类型出现的次数
  19. CASE函数
  20. 通过Headless模式执行selenium脚本

热门文章

  1. PCB CE工具取Genesis JOB与STEP内存地址 方法分享
  2. css bug(ie6兼容问题)
  3. bzoj4247: 挂饰(背包dp)
  4. A Few Words on Callbacks and Asynchronous Mechanism In Javascript
  5. [Apple开发者帐户帮助]六、配置应用服务(6)创建电子钱包标识符和证书
  6. CSS怎样改变行内样式(通过外部级联样式表) css !important用法CSS样式使用优先级判断
  7. Java系列学习(八)-继承
  8. PHP配置步骤
  9. JS——大小写转化
  10. FTP工作原理