diff --git a/modules/update/functions/pupdate b/modules/update/functions/pupdate new file mode 100644 index 00000000..5e8ecbb8 --- /dev/null +++ b/modules/update/functions/pupdate @@ -0,0 +1,54 @@ +# +# Updates Prezto to the latest version. +# +# Authors: +# Sorin Ionescu +# + +local remote_name +local remote_branch +local auto_commit +local use_color + +zstyle -s ':prezto:module:update:remote' name 'remote_name' +zstyle -s ':prezto:module:update:remote' branch 'remote_branch' +zstyle -t ':prezto:module:update' auto-commit && auto_commit='yes' +zstyle -t ':prezto:module:update:*' color && use_color='yes' + +if ! git \ + --git-dir="$(cd "${ZDOTDIR:-$HOME}/.zprezto" && git-root)" \ + --work-tree="${ZDOTDIR:-$HOME}/.zprezto" \ + pull \ + $(! is-true "$auto_commit" && print '--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 'Prezto has been updated to the latest version.' +print 'Follow me on GitHub at https://github.com/sorin-ionescu/prezto.' +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/modules/update/init.zsh b/modules/update/init.zsh new file mode 100644 index 00000000..53b26978 --- /dev/null +++ b/modules/update/init.zsh @@ -0,0 +1,24 @@ +# +# Updates Prezto periodically. +# +# Authors: +# Sorin Ionescu +# + +_updater_date_file="$HOME/.zupdate" +if zstyle -t ':prezto:module:update' auto-update; then + zstyle -s ':prezto:module:update' frequency '_updater_check_frequency' + + # Initialize the update reminder. + if [[ ! -f "$_updater_date_file" ]]; then + touch "$_updater_date_file" + fi + + # Check for update every 7 days. + if [[ "$_updater_date_file"(Nm+$_updater_check_frequency) ]]; then + pupdate && touch "$_updater_date_file" + fi +fi + +unset _updater_{date_file,check_frequency} + diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index ee5aa0d3..89a5f26f 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -141,3 +141,22 @@ zstyle ':prezto:module:terminal' auto-title 'yes' # Auto start a session when Zsh is launched in a SSH connection. # zstyle ':prezto:module:tmux:auto-start' remote 'yes' +# +# Update +# + +# Auto update to the latest version. +zstyle ':prezto:module:update' auto-update 'no' + +# Auto commit updated files without review. +zstyle ':prezto:module:update' auto-commit 'no' + +# Set the update frequency in days. +zstyle ':prezto:module:update' check-frequency '7' + +# Set the name of the update remote. +zstyle ':prezto:module:update:remote' name 'origin' + +# Set the branch of the update remote. +zstyle ':prezto:module:update:remote' branch 'master' +