如何在我的bash脚本中执行`omz update`命令?

3

我正在编写一个bash脚本来更新oh-my-zsh和插件。文件名: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

然而,如果我运行 bash update_omz_plugin.sh 命令,会得到以下结果:
update_omz_plugin.sh: line 9: omz: command not found

我认为这是因为omz是在source $ZSH/oh-my-zsh.sh中定义的函数。如何更新我的脚本以解决此问题,即使omz update正常工作?


2
你为什么期望Bash知道你的Zsh配置信息呢?也许可以尝试使用类似于“zsh -ic“omz update”这样的命令。 - tripleee
1
@tripleee 谢谢!zsh -ic“omz update”有效! - Zizheng Wu
2个回答

3
我在寻找为什么我的更新omz的脚本会重置并执行两次时遇到了这个问题。为了帮助任何需要的人,(当前的) OMZ常见问题解答中有一个专门针对这个问题的部分: 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).

当然,为了设置$ZSH,您应该按照 Robby Russel的接受回答在zsh脚本中运行;虽然我想您也可以手动解析它为/Users/my-user/.oh-my-zsh或任何其他路径。

1
你可以尝试将脚本的第一行改为:
#!/bin/zsh

omz函数是内置于Oh My Zsh中的,不会被/bin/bash加载。

然后运行zsh update_omz_plugin.sh


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接