Last active
November 25, 2024 07:44
-
-
Save 0xbillw/cd49406ee7bb852174ccf20860f06b18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
zshrc_file="$HOME/.zshrc" | |
omz_custom_plugin_home=${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins | |
append_plugin_to_zshrc() { | |
# The plugin to add | |
local new_plugin=$1 | |
# Check if the .zshrc file exists | |
if [ ! -f $zshrc_file ]; then | |
echo "$zshrc_file does not exist!" | |
exit 1 | |
fi | |
# Check and update the plugins configuration | |
if grep -qE "^plugins=\(.*\b${new_plugin}\b.*\)" "$zshrc_file"; then | |
echo "Plugin $new_plugin already exists in the plugins configuration." | |
else | |
sed -i -E "s/^plugins=\((.*)\)/plugins=(\1 $new_plugin)/" "$zshrc_file" | |
echo "Plugin $new_plugin has been successfully added to the plugins configuration." | |
fi | |
} | |
install_plugin() { | |
local plugin=$1 | |
local git_repo=$2 | |
local plugin_path="$omz_custom_plugin_home/$plugin" | |
if [ ! -e $plugin_path ]; then | |
echo "Install plugin $plugin" | |
git clone --depth 1 $git_repo $plugin_path | |
if [ $? != 0 ]; then | |
echo "git clone $git_repo failed" | |
exit 1 | |
fi | |
fi | |
append_plugin_to_zshrc $plugin | |
} | |
if ! command -v "zsh" >/dev/null 2>&1; then | |
echo "Install zsh first" | |
sudo apt install -y zsh | |
fi | |
if [ $? != 0 ]; then | |
echo "Zsh install failed" | |
exit 1 | |
fi | |
if [ ! -e ~/.oh-my-zsh ]; then | |
echo "Install oh-my-zsh" | |
sh -c "RUNZSH=no $(curl -fsSL https://install.ohmyz.sh/)" | |
if [ $? != 0 ]; then | |
echo "oh-my-zsh install failed" | |
exit 1 | |
fi | |
fi | |
install_plugin zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting.git | |
install_plugin zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions.git | |
if ! command -v "autojump" >/dev/null 2>&1; then | |
echo "Install plugin autojump" | |
sudo apt install -y autojump | |
fi | |
append_plugin_to_zshrc autojump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment