|
1 | 1 | # Plugin update check function
|
2 | 2 | auto_venv_update_check() {
|
3 |
| - local remote_tag local_tag repo_path user_input |
4 |
| - repo_path="${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-auto-venv" |
5 |
| - |
6 |
| - # Check if git is available, if not, skip update check |
7 |
| - if ! command -v git &> /dev/null; then |
8 |
| - # Skip the update check if git is not installed |
| 3 | + local update_file="$ZSH_CUSTOM/plugins/zsh-auto-venv/.last_update_check" |
| 4 | + local current_time=$(date +%s) |
| 5 | + local last_update_check |
| 6 | + |
| 7 | + if [[ -f "$update_file" ]]; then |
| 8 | + last_update_check=$(cat "$update_file") |
| 9 | + else |
| 10 | + last_update_check=0 |
| 11 | + fi |
| 12 | + |
| 13 | + # Check for updates every 24 hours (86400 seconds) |
| 14 | + if (( current_time - last_update_check < 86400 )); then |
| 15 | + # Last check was less than 24 hours ago, skip update check |
9 | 16 | return
|
10 | 17 | fi
|
11 | 18 |
|
12 |
| - # Fetch the latest tags from the remote, skip if fails |
| 19 | + # Record the time of this update check |
| 20 | + echo $current_time > "$update_file" |
| 21 | + |
| 22 | + # Proceed with the rest of the update check process... |
| 23 | + local remote_tag local_tag repo_path user_input |
| 24 | + repo_path="${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-auto-venv" |
| 25 | + |
| 26 | + # Skip update check if git is not installed |
| 27 | + if ! command -v git &> /dev/null; then return; fi |
| 28 | + |
| 29 | + # Skip if fails to fetch the latest tags from the remote |
13 | 30 | git -C "$repo_path" fetch --tags 2> /dev/null || return
|
14 | 31 |
|
15 |
| - # Get the latest tag name from the remote and local, continue only if both are retrieved |
| 32 | + # Continue only if both tags are retrieved successfully |
16 | 33 | remote_tag=$(git -C "$repo_path" describe --tags `git -C "$repo_path" rev-list --tags --max-count=1` 2> /dev/null)
|
17 | 34 | local_tag=$(git -C "$repo_path" describe --tags 2> /dev/null)
|
18 |
| - if [ -z "$remote_tag" ] || [ -z "$local_tag" ]; then |
19 |
| - # Skip the update process if unable to retrieve tags |
20 |
| - return |
21 |
| - fi |
| 35 | + if [ -z "$remote_tag" ] || [ -z "$local_tag" ]; then return; fi |
22 | 36 |
|
23 |
| - # Check if the latest tag matches the currently checked-out version |
| 37 | + # Notify user of new version and ask for update permission |
24 | 38 | if [ "$remote_tag" != "$local_tag" ]; then
|
25 | 39 | echo "New version available for zsh-auto-venv: $remote_tag (current version: $local_tag)"
|
26 | 40 | echo -n "Do you want to update the plugin now? [Y/n] "
|
|
0 commit comments