-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for updates once a week, on session start (#39)
* update checker test * tweak update checker * test * test * fix * test * test * test * uhh * debug * test exit * test * update last check * test * update check * test * fix * test * test * test * test * test * test * test * test * test * test * test * lmao * test * test * fake update * bump version * 1 day lock * test * add branch status * update branch status * yeet * remove text * yeet * prettier on changelong * update changelog
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
#Based on https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/check_for_upgrade.sh | ||
if [[ "$OMC_DISABLE_AUTO_UPDATE" = true ]] \ | ||
|| ! command -v git &>/dev/null; then | ||
return | ||
fi | ||
OMC_EPOCH=$(date +%s) | ||
set +x | ||
function current_epoch() { | ||
echo $(($OMC_EPOCH/60/60/24)) | ||
} | ||
|
||
function update_last_updated_file() { | ||
echo "LAST_EPOCH=$(current_epoch)" > "${OH_MY_COMMA_PATH}/log/.omc-update" | ||
} | ||
|
||
# Remove lock directory if older than a day | ||
if mtime=$(date +%s -r "$OH_MY_COMMA_PATH/log/update.lock" 2>/dev/null); then | ||
if (( (mtime + 3600 * 24) < OMC_EPOCH )); then | ||
command rm -rf "$OH_MY_COMMA_PATH/log/update.lock" | ||
fi | ||
fi | ||
|
||
# Check for lock directory | ||
if ! command mkdir "$OH_MY_COMMA_PATH/log/update.lock" 2>/dev/null; then | ||
return | ||
fi | ||
|
||
# Remove lock directory on exit. `return 1` is important for when trapping a SIGINT: | ||
# The return status from the function is handled specially. If it is zero, the signal is | ||
# assumed to have been handled, and execution continues normally. Otherwise, the shell | ||
# will behave as interrupted except that the return status of the trap is retained. | ||
trap "command rm -rf '$OH_MY_COMMA_PATH/log/update.lock'; return" EXIT INT QUIT | ||
|
||
# Create or update .omc-update file if missing or malformed | ||
if ! source "${OH_MY_COMMA_PATH}/log/.omc-update" 2>/dev/null || [[ -z "$LAST_EPOCH" ]]; then | ||
touch ${OH_MY_COMMA_PATH}/log/.omc-update | ||
update_last_updated_file | ||
fi | ||
|
||
# Number of days before trying to update again | ||
epoch_target=${OMC_AUTOUPDATE_DAYS:-7} | ||
# Test if enough time has passed until the next update | ||
if (( ( $(current_epoch) - LAST_EPOCH ) < $epoch_target )); then | ||
return | ||
fi | ||
|
||
cd ${OH_MY_COMMA_PATH} | ||
|
||
git fetch | ||
OMC_UPSTREAM=${1:-'@{u}'} | ||
OMC_LOCAL=$(git rev-parse @) | ||
OMC_REMOTE=$(git rev-parse "$OMC_UPSTREAM") | ||
|
||
if [ $OMC_LOCAL != $OMC_REMOTE ]; then | ||
# Ask for confirmation before updating unless disabled | ||
if [[ "$OMC_DISABLE_UPDATE_PROMPT" = true ]]; then | ||
emu update | ||
else | ||
echo "[emu.sh] Current .oh-my-comma branch: $(git branch | head -n 1)" | ||
echo "$(git status | head -n 2 | tail -n 1)" | ||
# input sink to swallow all characters typed before the prompt | ||
# and add a newline if there wasn't one after characters typed | ||
read -r -p "[emu.sh] Update .oh-my-comma? [Y/n] " option | ||
[[ "$option" != $'\n' ]] && echo | ||
case "$option" in | ||
[yY$'\n']) emu update && update_last_updated_file ;; | ||
[nN]) update_last_updated_file ;; | ||
*) emu update ;; | ||
esac | ||
fi | ||
fi | ||
cd - | ||
unset -f current_epoch update_last_updated_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ function emu(){ # main wrapper function | |
_updateohmycomma | ||
fi | ||
} | ||
|
||
source ${OH_MY_COMMA_PATH}/check-for-updates.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/** | ||
** | ||
!.gitignore |