Files
TerminalPolyjuice/zsh/install_ohmyzsh.sh
2025-04-21 16:39:45 +08:00

109 lines
3.6 KiB
Bash

#! /bin/bash
echo "$SHELL" | grep -q zsh
if [ $? -ne 0 ]; then
echo "Please run this script in zsh shell."
exit 1
fi
# git, fzf, zoxide are required
if ! command -v git >/dev/null 2>&1; then
echo "Git is not installed."
exit 1
fi
if ! command -v fzf >/dev/null 2>&1; then
echo "FZF is not installed."
exit 1
fi
if ! command -v zoxide >/dev/null 2>&1; then
echo "Zoxide is not installed."
exit 1
fi
if ! command -v python >/dev/null 2>&1; then
echo "Zoxide is not installed."
exit 1
fi
# Path
PATH_OHMYZSH="$HOME"/.oh-my-zsh
PATH_OHMYZSH_CUSTOM_PLUGINS="$PATH_OHMYZSH"/custom/plugins
PATH_OHMYZSH_CUSTOM_THEMES="$PATH_OHMYZSH"/custom/themes
# git clone oh-my-zsh
if [ ! -d "$PATH_OHMYZSH" ]; then
echo "Oh My Zsh is not downloaded. Downloading..."
git clone https://github.com/ohmyzsh/ohmyzsh.git "$PATH_OHMYZSH"
else
cd "$PATH_OHMYZSH" || exit 2
if [ ! -d .git ]; then
echo "Oh My Zsh is not a git repository. Please remove $PATH_OHMYZSH and try again."
exit 1
else
echo "Oh My Zsh is already exist. Updating..."
git pull
fi
fi
# git clone zsh-autosuggestions
if [ ! -d "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions ]; then
echo "Zsh Autosuggestions is not downloaded. Downloading..."
git clone https://github.com/zsh-users/zsh-autosuggestions.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions
else
cd "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions || exit 1
if [ ! -d .git ]; then
echo "Zsh Autosuggestions is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_PLUGINS/zsh-autosuggestions and try again."
exit 1
else
echo "Zsh Autosuggestions is already exist. Updating..."
git pull
fi
fi
# git clone zsh-syntax-highlighting
if [ ! -d "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting ]; then
echo "Zsh Syntax Highlighting is not downloaded. Downloading..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting
else
cd "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting || exit 1
if [ ! -d .git ]; then
echo "Zsh Syntax Highlighting is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_PLUGINS/zsh-syntax-highlighting and try again."
exit 1
else
echo "Zsh Syntax Highlighting is already exist. Updating..."
git pull
fi
fi
# git clone zsh-autocomplete
if [ ! -d "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete ]; then
echo "Zsh Autocomplete is not downloaded. Downloading..."
git clone https://github.com/marlonrichert/zsh-autocomplete.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete
else
cd "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete || exit 1
if [ ! -d .git ]; then
echo "Zsh Autocomplete is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_PLUGINS/zsh-autocomplete and try again."
exit 1
else
echo "Zsh Autocomplete is already exist. Updating..."
git pull
fi
fi
# git clone powerlevel10k
if [ ! -d "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k ]; then
echo "Powerlevel10k is not downloaded. Downloading..."
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k
else
cd "$PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k" || exit 1
if [ ! -d .git ]; then
echo "Zsh Autocomplete is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k and try again."
exit 1
else
echo "Powerlevel10k is already exist. Updating..."
git pull
fi
fi