Skip to content

Commit

Permalink
Add auto-update functionality
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
rcloran committed Oct 10, 2023
1 parent 7494355 commit 8902235
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ To run `znap pull` on specific repos only, including ones you have set to be exc
% znap pull <repo> ...
```

To be prompted to automatically update with `znap pull` every 30 days, add the following to your `.zshrc` file:
```sh
zstyle ':znap:pull' auto-update 30
```

## `.zshrc` optimization
Using Znap to optimize your Zsh config can be as simple as this:
```sh
Expand Down
21 changes: 21 additions & 0 deletions functions/..znap.auto-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/zsh

zmodload zsh/datetime

local update_file=${XDG_STATE_HOME}/znap/last-update
if [[ ! -f "${update_file}" ]] ; then
echo $EPOCHSECONDS > "${update_file}"
return 0
fi

local -F interval
zstyle -s ':znap:pull' auto-update interval

local last_update=$(< "${update_file}")
(( last_update + (interval * 86400) < EPOCHSECONDS )) || return 0

read -q "?Update znap? [y/N] " _ || { echo ; return 0 }
echo

.znap.pull
echo $EPOCHSECONDS > "${update_file}"
4 changes: 4 additions & 0 deletions scripts/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ zstyle -T :znap: auto-compile &&
add-zsh-hook preexec ..znap.auto-compile
add-zsh-hook zsh_directory_name ..znap.dirname

if zstyle -s ':znap:pull' auto-update _ ; then
..znap.auto-update
fi

typeset -gH _comp_dumpfile=${_comp_dumpfile:-$XDG_CACHE_HOME/zsh/compdump}
[[ -f $_comp_dumpfile && ${${:-${ZDOTDIR:-$HOME}/.zshrc}:P} -nt $_comp_dumpfile ]] &&
zf_rm -f $_comp_dumpfile
Expand Down

0 comments on commit 8902235

Please sign in to comment.