我有自己的自定义主题为Oh My Zsh,它位于.oh-my-zsh/custom
文件夹中。我把它托管在GitHub上(如Version control of customizations下的OMZ文档中所述)所以我所要做的就是
cd ~/.oh-my-zsh/custom ; git pull ; popd
并且它更新正常但我必须访问我使用此自定义主题的每台机器/ VM并手动运行命令。如何绑定Oh My Zsh的自动更新系统以更新我的自定义主题?
答案 0 :(得分:0)
在尝试提供一个大部分被忽略的拉取请求后,我破解了一种方法来绑定Oh My Zsh的更新。通过观察.git的FETCH_HEAD文件的mod日期,我可以在每次Oh My Zsh从github获取时触发我的更新,这对我来说已经足够了。
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# self-update
ts_file=~/.zsh-custom-update
upgrade_custom() {
printf '\033[0;34m%s\033[0m\n' "Upgrading the custom files"
cd "$ZSH_CUSTOM"
if git pull --rebase --stat origin master
then
printf '\033[0;34m%s\033[0m\n' 'Hooray! The custom files have been updated and/or are at the current version.'
else
printf '\033[0;31m%s\033[0m\n' 'There was an error updating. Try again later?'
fi
}
upgrade_custom_update() {
echo -n "$1" >! $ts_file
}
upgrade_custom_check() {
if [[ "$OSTYPE" == darwin* ]]; then
ts=$(stat -f '%Sm' $ZSH/.git/FETCH_HEAD || echo 'missing' )
else
ts=$(stat -c %y $ZSH/.git/FETCH_HEAD || echo 'missing' )
fi
if [[ "$ts" == $( cat $ts_file || echo 'missing' ) ]] ; then
#echo 'up to date'
else
upgrade_custom_update "$ts"
upgrade_custom
fi
}
upgrade_custom_check
我对编写zsh脚本缺乏经验,因此欢迎提供反馈。我同时使用Mac和Mac Linux,但我不确定stat命令是否适用于BSD。