給sunpinyin加速
阿新 • • 發佈:2017-07-01
one pri blog nal logs 方式 don code cache
因為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/.sunpinyinsunpinyin_speed_up" 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 0 } # 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 placein 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=0 while [ true ] do p_count=$(($p_count+1)) sleep 1800 if [ $p_count == 4 ] then p_count=0 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+512)) if [ $p_size_shm -ge $p_size_real ] then cp -f "${SHM_USERDICT}" "${SUN_DIR}/userdict.real" fi done
之後將其設置為開機啟動就好了。
因為我們用systemd的方式,所以需要再寫一個開機啟動的服務放到/etc/systemd/system/中。
[Unit] Description=Sunpinyin dict cache [Service] ExecStart=/home/xuzhenan/mysh/sunpinyin_speed_up [Install] WantedBy=multi-user.targetsunpinyin_speed_up.service
之後運行
sudo systemctl enable sunpinyin_speed_up.service
將其設置為開機自啟動就好了。
給sunpinyin加速