I'm writing a bash script to update oh-my-zsh & plugins. file: update_omz_plugin.sh
:
#!/bin/bash
ZPLUGINDIR=$HOME/.oh-my-zsh/custom/plugins
ZTHEMEDIR=$HOME/.oh-my-zsh/custom/themes
if cd $ZPLUGINDIR/fast-syntax-highlighting; then git pull; else git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git $ZPLUGINDIR/fast-syntax-highlighting; fi
if cd $ZTHEMEDIR/powerlevel10k; then git pull; else git clone https://github.com/romkatv/powerlevel10k.git $ZTHEMEDIR/powerlevel10k; fi
omz update
However, if I do bash update_omz_plugin.sh
, I got
update_omz_plugin.sh: line 9: omz: command not found
I thought this is because omz
is a function defined in source $ZSH/oh-my-zsh.sh
? How can I update my script to solve this issue, i.e., make omz update
work?
I ran into this question when looking for why my script that updated omz was resetting and executing twice. For whomever it may help, the (current) OMZ FAQ has a section just for this: how-do-i-manually-update-oh-my-zsh-from-a-script:
The best way to do that is to call the
upgrade.sh
script directly. If$ZSH
is defined (it should point to where OMZ is installed), then you can call it like so:"$ZSH/tools/upgrade.sh"
The
omz update
command ... restarts the zsh session (which might cause a restart loop).
Of course, in order to have $ZSH
set you should be running in a zsh script as per the accepted answer by Robby Russel; Although I suppose you could manually resolve it to /Users/my-user/.oh-my-zsh
or whatever.