Last active
April 23, 2025 05:19
-
-
Save pedoc/0acd417a5da202d22bf7b46607be8d86 to your computer and use it in GitHub Desktop.
Automatically install and configure zsh with one key
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 | |
set -e | |
PROXY="http://192.168.1.2:10808" | |
export https_proxy=$PROXY | |
export http_proxy=$PROXY | |
ARCH=$(uname -m) | |
case "$ARCH" in | |
x86_64) | |
FZF_ARCH="linux_amd64" | |
;; | |
aarch64 | arm64) | |
FZF_ARCH="linux_arm64" | |
;; | |
armv7l) | |
FZF_ARCH="linux_arm" | |
;; | |
*) | |
echo "No supported arch: $ARCH" >&2 | |
exit 1 | |
;; | |
esac | |
if command -v yum &>/dev/null; then | |
PACKAGE_MANAGER="yum" | |
elif command -v apt &>/dev/null; then | |
PACKAGE_MANAGER="apt" | |
elif command -v pacman &>/dev/null; then | |
PACKAGE_MANAGER="pacman" | |
elif command -v dnf &>/dev/null; then | |
PACKAGE_MANAGER="dnf" | |
elif command -v zypper &>/dev/null; then | |
PACKAGE_MANAGER="zypper" | |
elif command -v pkg &>/dev/null; then | |
PACKAGE_MANAGER="pkg" | |
else | |
echo "No supported package manager found." | |
exit 1 | |
fi | |
echo "Package manager for this system is: $PACKAGE_MANAGER" | |
PACKAGES=(wget zsh git curl) | |
if [ "$PACKAGE_MANAGER" == "yum" ]; then | |
# sudo yum update -y | |
sudo yum makecache | |
sudo yum install -y "${PACKAGES[@]}" | |
elif [ "$PACKAGE_MANAGER" == "apt" ]; then | |
sed -i '/^deb cdrom:/s/^/#/' /etc/apt/sources.list || true | |
apt update | |
apt install -y sudo | |
apt install -y "${PACKAGES[@]}" | |
elif [ "$PACKAGE_MANAGER" == "pacman" ]; then | |
sudo pacman -Syu "${PACKAGES[@]}" | |
elif [ "$PACKAGE_MANAGER" == "dnf" ]; then | |
sudo dnf install -y "${PACKAGES[@]}" | |
elif [ "$PACKAGE_MANAGER" == "zypper" ]; then | |
sudo zypper install -y "${PACKAGES[@]}" | |
elif [ "$PACKAGE_MANAGER" == "pkg" ]; then | |
sudo pkg install "${PACKAGES[@]}" | |
fi | |
# shellcheck disable=SC2128 | |
echo "Packages: $PACKAGES installed successfully." | |
FZF_VERSION="0.61.3" # working with glibc 2.28 | |
FZF_ARCHIVE_FILE="fzf-${FZF_VERSION}-${FZF_ARCH}.tar.gz" | |
FZF_DOWNLOAD_URL="https://github.com/junegunn/fzf/releases/download/v${FZF_VERSION}/${FZF_ARCHIVE_FILE}" | |
echo "Installing fzf $FZF_VERSION from $FZF_DOWNLOAD_URL" | |
wget "$FZF_DOWNLOAD_URL" -O "$FZF_ARCHIVE_FILE" | |
tar -xvzf "$FZF_ARCHIVE_FILE" | |
mv -f ./fzf /usr/bin/fzf | |
rm -f "$FZF_ARCHIVE_FILE" | |
echo "fzf installed successfully. $(fzf --version)" | |
echo "Installing Oh My Zsh..." | |
OH_MY_ZSH_DIR="$HOME/.oh-my-zsh" | |
if [ -d "$OH_MY_ZSH_DIR" ]; then | |
echo "$OH_MY_ZSH_DIR exists. delete?[y/N]" | |
read -r confirm | |
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then | |
echo "delete $OH_MY_ZSH_DIR..." | |
# rm -rf "$OH_MY_ZSH_DIR" | |
mv "$OH_MY_ZSH_DIR" "$OH_MY_ZSH_DIR.bak" | |
echo "backup $OH_MY_ZSH_DIR to $OH_MY_ZSH_DIR.bak" | |
else | |
echo "User chose not to delete $OH_MY_ZSH_DIR. Exiting." | |
exit 1 | |
fi | |
fi | |
# curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash | |
#ZSH=~/.zsh | |
# ( | |
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
# ) | |
git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$OH_MY_ZSH_DIR" | |
cp "$OH_MY_ZSH_DIR/templates/zshrc.zsh-template" ~/.zshrc | |
echo "Oh My Zsh installed successfully. ZSH=$ZSH" | |
PLUGINS_HOME=$OH_MY_ZSH_DIR/custom/plugins | |
THEMES_HOME=$OH_MY_ZSH_DIR/custom/themes | |
if [ ! -d "$PLUGINS_HOME" ]; then | |
mkdir -p "$PLUGINS_HOME" | |
fi | |
echo "Installing plugins to $PLUGINS_HOME ..." | |
git clone --depth=1 https://github.com/Aloxaf/fzf-tab "$PLUGINS_HOME/fzf-tab" | |
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "$PLUGINS_HOME/zsh-autosuggestions" | |
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "$PLUGINS_HOME/zsh-syntax-highlighting" | |
git clone --depth=1 https://github.com/zsh-users/zsh-completions "$PLUGINS_HOME/zsh-completions" | |
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$THEMES_HOME/powerlevel10k" | |
echo "Enabling plugins in .zshrc..." | |
sed -i 's/^plugins=(\(.*\))/plugins=(\1 z fzf fzf-tab zsh-autosuggestions zsh-syntax-highlighting zsh-completions sudo aliases docker)/' ~/.zshrc | |
echo "Enabling powerlevel10k theme in .zshrc..." | |
sed -i 's/^ZSH_THEME=".*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc | |
echo "Change default shell to zsh..." | |
sudo chsh -s $(which zsh) | |
# shellcheck disable=SC1090 | |
# source ~/.zshrc | |
echo "Installation complete! $(zsh --version)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment