diff --git a/functions/update-omz b/functions/update-omz new file mode 100755 index 00000000..340e6dc8 --- /dev/null +++ b/functions/update-omz @@ -0,0 +1,23 @@ +# Jonathan Dahan + +# To auto-commit changes from upstream without review (dangerous!), add to your zshrc: +# +# zstyle ':omz:function:update-omz' auto-commit 'yes' +# +# This will still favor local changes when there are conflicts + +current_path=$PWD +cd $HOME/.oh-my-zsh + +zstyle -t ':omz:function:update-omz' auto-commit || local nocommit='--no-commit' + +if git pull $nocommit --strategy=recursive -X ours origin master; then + zstyle -t ':omz:function:update-omz' color && printf "$FG[blue]" + printf 'Hooray! oh-my-zsh is up-to-date :)' + touch ~/.omz-update +else + zstyle -t ':omz:function:update-omz' color && printf "$FG[red]" + printf 'Oh no! There was an error updating oh-my-zsh :(' +fi + +cd "$current_path" diff --git a/plugins/auto-update/init.zsh b/plugins/auto-update/init.zsh index 7f37f35c..e517340e 100644 --- a/plugins/auto-update/init.zsh +++ b/plugins/auto-update/init.zsh @@ -1,40 +1,13 @@ -# Updates oh-my-zsh. +# Auto-update zsh if its over 6 hours old # Jonathan Dahan -# This plugin adds auto-update support to omz. -# -# zstyle ':omz:plugin:update-omz' auto-commit 'yes' -# auto-commit will commit whatever upstream changes there are without review -# This will still favor local changes when conflict arive -# -# zstyle ':omz:plugin:update-omz' auto-update 'yes' -# auto-update will check for updates 6 hours from the last successful upgrade +# Take a look at the update-omz options in functions/ -function update-omz() { - current_path=$PWD - cd $HOME/.oh-my-zsh - - zstyle -t ':omz:plugin:update-omz' auto-commit || local nocommit='--no-commit' - - if git pull $nocommit --strategy=recursive -X ours origin master; then - zstyle -t ':omz:plugin:update-omz' color && printf "$FG[blue]" - printf 'Hooray! oh-my-zsh is up-to-date :)' - touch ~/.omz-update - else - zstyle -t ':omz:plugin:update-omz' color && printf "$FG[red]" - printf 'Oh no! There was an error updating oh-my-zsh :(' - fi - - cd "$current_path" -} - -if zstyle -t ':omz:plugin:update-omz' auto-update; then - if [ -f ~/.omz-update ]; then - # update if ~/.omz-update was modified over 6 hours ago - if [ ~/.omz-update(Nmh+6) ]; then - update-omz - fi - else +if [ -f ~/.omz-update ]; then + # update if ~/.omz-update was modified over 6 hours ago + if [ ~/.omz-update(Nmh+6) ]; then update-omz fi +else + update-omz fi