I've installed Oh My Zsh with a few custom plugins, such as zsh-autosuggestions. Now while Oh My Zsh supports automatic updates, this doesn't apply to custom plugins (installed to the custom/ subdirectory). How can I make Oh My Zsh update those as well?
Asked
Active
Viewed 1.0k times
11
Eugene Yarmash
- 14,675
- 14
- 50
- 57
4 Answers
14
Oh My Zsh upgrades are handled by the $ZSH/tools/upgrade.sh script. To update any custom plugins (assuming those are Git clones), you can add these lines to the end of the script before the exit command:
printf "\n${BLUE}%s${RESET}\n" "Updating custom plugins"
cd custom/plugins
for plugin in */; do
if [ -d "$plugin/.git" ]; then
printf "${YELLOW}%s${RESET}\n" "${plugin%/}"
git -C "$plugin" pull
fi
done
Now, whenever Oh My Zsh is updated, your custom plugins will be updated too.
Eugene Yarmash
- 14,675
- 14
- 50
- 57
-
12why isn't this part of OhMyZSH? – Woodstock Mar 16 '20 at 13:04
-
Should I put it before `exit $status` in the `$ZSH/tools/upgrade.sh` file? – alper Sep 10 '20 at 10:47
-
1@alper: Yes. That `exit` call seems a recent addition to the upgrade script. – Eugene Yarmash Sep 10 '20 at 14:57
-
Won't this get removed if oh-my-zsh updates this file? – 17xande Jun 22 '22 at 17:34
-
Just install the "autoupdate" plugin – rsalmei Nov 17 '22 at 16:23
3
You can do this by using the autoupdate plugin.
Simply download it as a regular custom plugin, and add it to the plugins array in your .zshrc file:
plugins=(
...
autoupdate
)
Follow the instructions in their README to find out how to customize the update frequency
smac89
- 1,279
- 1
- 13
- 17
-
Does it work for you? I've installed and enabled it, reloaded zsh, but still no updates on `upgrade_oh_my_zsh` – Eugene Yarmash Jul 01 '21 at 06:50
-
@EugeneYarmash try `upgrade_ohl_my_zsh` or `upgrade_oh_my_zsh_custom` – JCallicoat Jul 15 '21 at 03:23
2
Small expansion on Eugene's great answer. This will also update any themes you have:
# $ZSH/tools/upgrade.sh
...
printf "\n${BLUE}%s${RESET}\n" "Updating custom plugins and themes"
cd custom/
for plugin in plugins/*/ themes/*/; do
if [ -d "$plugin/.git" ]; then
printf "${YELLOW}%s${RESET}\n" "${plugin%/}"
git -C "$plugin" pull
fi
done
Hubert Grzeskowiak
- 320
- 4
- 13
-
In the case, there is not custom themes or plugins inside the folder it will crash. Maybe add a check could be safer – PierBJX Mar 22 '23 at 01:54