Skip to content

Commit

Permalink
Added possibility to chech for filechanges on init
Browse files Browse the repository at this point in the history
Allow multiple files to be checked by defining an array
  • Loading branch information
m42e committed Jul 20, 2015
1 parent 111f9e3 commit 16f7a69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Returns 0 if an init script exists.
#### Update all repositories and remove the init script
zgen update

#### Automatically check for filechanges and regenerate zinit
You can set the environment variable ZGEN_RESET_ON_CHANGE. These files will be checked and if a change is detected zgen reset is called.
ZGEN_RESET_ON_CHANGE=(${HOME}/.zshrc ${HOME}/.zshrc.local)

### Example .zshrc

```zsh
Expand Down
16 changes: 16 additions & 0 deletions zgen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ zgen-save() {
echo "#" >> "${ZGEN_INIT}"
echo "fpath=(${(q)ZGEN_COMPLETIONS[@]} \${fpath})" >> "${ZGEN_INIT}"

# check for file changes
if [[ ! -z ${ZGEN_RESET_ON_CHANGE} ]]; then
echo >> "${ZGEN_INIT}"
echo "# check for file changes" >> "${ZGEN_INIT}"
for file in ${ZGEN_RESET_ON_CHANGE}; do
CHANGESHA=`shasum -a 256 ${file}`
echo "if [[ \"\`shasum -a 256 ${file}\`\" != \"$CHANGESHA\" ]]; then" >> "${ZGEN_INIT}"
echo " echo Changed file ${file}, resetting zgen" >> "${ZGEN_INIT}"
echo " zgen reset" >> "${ZGEN_INIT}"
echo -n "el" >> "${ZGEN_INIT}"
done
echo "se " >> "${ZGEN_INIT}"
echo " ;" >> "${ZGEN_INIT}"
echo "fi" >> "${ZGEN_INIT}"
fi

zgen-apply --verbose
}

Expand Down

0 comments on commit 16f7a69

Please sign in to comment.