29b99c2c7b16f22f3ca2bdf9478ba700ac6c48b5
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
2index 3210e437531a0bf8de978e9cdbc9a2e2407cf163..1cc193bde045bdb911570b8f8ceb41c4601a5d1b 100644
3--- a/tools/check_for_upgrade.sh
4+++ b/tools/check_for_upgrade.sh
5@@ -9,6 +9,7 @@ fi
6 # - prompt (default): the user is asked before updating when it's time to update
7 # - auto: the update is performed automatically when it's time
8 # - reminder: a reminder is shown to the user when it's time to update
9+# - background-alpha: an experimental update-on-the-background option
10 # - disabled: automatic update is turned off
11 zstyle -s ':omz:update' mode update_mode || {
12 update_mode=prompt
13@@ -91,13 +92,37 @@ function is_update_available() {
14 }
15
16 function update_last_updated_file() {
17- echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update"
18+ local exit_status="$1" error="$2"
19+
20+ if [[ -z "${1}${2}" ]]; then
21+ echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update"
22+ return
23+ fi
24+
25+ cat >! "${ZSH_CACHE_DIR}/.zsh-update" <<EOD
26+LAST_EPOCH=$(current_epoch)
27+EXIT_STATUS=${exit_status}
28+ERROR='${error//\'/’}'
29+EOD
30 }
31
32 function update_ohmyzsh() {
33+ local verbose_mode
34 zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
35- if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then
36+
37+ if [[ "$update_mode" != background-alpha ]] \
38+ && LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then
39 update_last_updated_file
40+ return $?
41+ fi
42+
43+ local exit_status error
44+ if error=$(LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v silent 2>&1); then
45+ update_last_updated_file 0 "Update successful"
46+ else
47+ exit_status=$?
48+ update_last_updated_file $exit_status "$error"
49+ return $exit_status
50 fi
51 }
52
53@@ -126,88 +151,145 @@ function has_typed_input() {
54 }
55 }
56
57-() {
58- emulate -L zsh
59+function handle_update() {
60+ () {
61+ emulate -L zsh
62
63- local epoch_target mtime option LAST_EPOCH
64+ local epoch_target mtime option LAST_EPOCH
65
66- # Remove lock directory if older than a day
67- zmodload zsh/datetime
68- zmodload -F zsh/stat b:zstat
69- if mtime=$(zstat +mtime "$ZSH/log/update.lock" 2>/dev/null); then
70- if (( (mtime + 3600 * 24) < EPOCHSECONDS )); then
71- command rm -rf "$ZSH/log/update.lock"
72+ # Remove lock directory if older than a day
73+ zmodload zsh/datetime
74+ zmodload -F zsh/stat b:zstat
75+ if mtime=$(zstat +mtime "$ZSH/log/update.lock" 2>/dev/null); then
76+ if (( (mtime + 3600 * 24) < EPOCHSECONDS )); then
77+ command rm -rf "$ZSH/log/update.lock"
78+ fi
79 fi
80- fi
81
82- # Check for lock directory
83- if ! command mkdir "$ZSH/log/update.lock" 2>/dev/null; then
84- return
85- fi
86+ # Check for lock directory
87+ if ! command mkdir "$ZSH/log/update.lock" 2>/dev/null; then
88+ return
89+ fi
90
91- # Remove lock directory on exit. `return $ret` is important for when trapping a SIGINT:
92- # The return status from the function is handled specially. If it is zero, the signal is
93- # assumed to have been handled, and execution continues normally. Otherwise, the shell
94- # will behave as interrupted except that the return status of the trap is retained.
95- # This means that for a CTRL+C, the trap needs to return the same exit status so that
96- # the shell actually exits what it's running.
97- trap "
98- ret=\$?
99- unset update_mode
100- unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh 2>/dev/null
101- command rm -rf '$ZSH/log/update.lock'
102- return \$ret
103- " EXIT INT QUIT
104-