Files
TerminalPolyjuice/zsh/install_ohmyzsh.sh
2025-04-28 20:42:10 +08:00

144 lines
4.9 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
if ! command -v python3 >/dev/null 2>&1; then
echo "Python is not installed."
exit 1
fi
fi
if ! command -v starship >/dev/null 2>&1; then
echo "Starship 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"
git clone https://gitee.com/mirrors/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
git clone https://gitee.com/mirrors/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
git clone https://gitee.com/mirrors/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
git clone https://gitee.com/mirrors/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
# git clone --depth=1 https://gitee.com/gwbeip/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
# copying $HOME/.zshrc
current_dir=$(dirname $(realpath "$0"))
if [ -f "$HOME/.zshrc" ]; then
if $(file "$HOME/.zshrc" | grep -q "symbolic link") ; then
if [[ $(readlink "$HOME/.zshrc") != "$current_dir/zshrc" ]]; then
ln -sf "$current_dir/zshrc" "$HOME/.zshrc"
fi
else
if [ ! -f "$HOME/.zshrc.bkp" ]; then
mv "$HOME/.zshrc" "$HOME/.zshrc.bkp"
ln -s "$current_dir/zshrc" "$HOME/.zshrc"
else
echo "Backup file already exists. Please remove $HOME/.zshrc.bkp and try again."
exit 1
fi
fi
else
ln -s "$current_dir/zshrc" "$HOME/.zshrc"
fi