From 82fe11ee1b8c13291c473f2991f41d4013707cb6 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Fri, 27 Jan 2012 13:00:05 -0500 Subject: [PATCH] Added auto update. --- functions/omz-update | 49 ++++++++++++++++++++++++++++++++++++++++++++ init.zsh | 15 ++++++++++++++ templates/zshrc.zsh | 12 +++++++++++ 3 files changed, 76 insertions(+) create mode 100644 functions/omz-update diff --git a/functions/omz-update b/functions/omz-update new file mode 100644 index 00000000..1eae89d5 --- /dev/null +++ b/functions/omz-update @@ -0,0 +1,49 @@ +# Sorin Ionescu + +local remote_name +local remote_branch +local auto_commit +local use_color + +zstyle -s ':omz:updater:remote' name 'remote_name' +zstyle -s ':omz:updater:remote' branch 'remote_branch' +zstyle -t ':omz:updater:auto' commit && auto_commit='yes' +zstyle -t ':omz:updater:*' color && use_color='yes' + +if ! git \ + --git-dir="${OMZ}/.git" \ + --work-tree="$OMZ" \ + pull \ + "${auto_commit:---no-commit}" \ + --strategy=recursive \ + -X ours \ + "${remote_name:-origin}" \ + "${remote_branch:-master}" 2> /dev/null +then + is-true "$use_color" && printf "$FG[red]" + print 'There was an error updating. Try again later?' + is-true "$use_color" && printf "$FG[none]" + return 1 +fi + +is-true "$use_color" && printf "$FG[green]" +printf '%s' \ +' __ __ __ + ____ / /_ ____ ___ __ __ ____ _____ / /_ / / + / __ \ / __ \ / __ `__ \ / / / / /_ / / ___// __ \ / / +/ /_/ // / / / / / / / / // /_/ / / /_ (__ )/ / / / /_/ +\____//_/ /_/ /_/ /_/ /_/ \__, / /___//____//_/ /_/ (_) + /____/ +' +is-true "$use_color" && printf "$FG[cyan]" +print +print 'Oh My Zsh has been updated to the latest version.' +print 'Follow us on Twitter: http://twitter.com/ohmyzsh.' +if ! is-true "$auto_commit"; then + is-true "$use_color" && printf "$FG[yellow]" + print + print 'Updates must be manually commited.' +fi +print +is-true "$use_color" && printf "$FG[none]" +return 0 diff --git a/init.zsh b/init.zsh index 9125d8d0..0e2c001e 100644 --- a/init.zsh +++ b/init.zsh @@ -88,6 +88,21 @@ zstyle -a ':omz:prompt' theme 'prompt_argv' prompt "$prompt_argv[@]" unset prompt_argv +# Auto-update Zsh every week. +omz_update="$HOME/.zomzupdate" +if zstyle -t ':omz:updater:auto' update; then + # Initialize the update reminder. + if [[ ! -f "$omz_update" ]]; then + touch "$omz_update" + fi + + # Check for update every 7 days. + if [ "$omz_update"(Nmd+7) ]; then + update-omz && touch "$omz_update" + fi +fi +unset omz_update + # Compile the completion dump, to increase startup speed. dump_file="$HOME/.zcompdump" if [[ "$dump_file" -nt "${dump_file}.zwc" || ! -f "${dump_file}.zwc" ]]; then diff --git a/templates/zshrc.zsh b/templates/zshrc.zsh index c177862f..e685220e 100644 --- a/templates/zshrc.zsh +++ b/templates/zshrc.zsh @@ -21,6 +21,18 @@ zstyle ':omz:load' plugin 'archive' 'git' # Auto set to 'off' on dumb terminals. zstyle ':omz:prompt' theme 'sorin' +# Auto update to the latest version. +zstyle ':omz:updater:auto' update 'no' + +# Auto commit updated files without review. +zstyle ':omz:updater:auto' commit 'no' + +# Set the name of the update remote. +zstyle ':omz:updater:remote' name 'origin' + +# Set the branch of the update remote. +zstyle ':omz:updater:remote' branch 'master' + # This will make you shout: OH MY ZSHELL! source "$HOME/.oh-my-zsh/init.zsh"