Last active
March 9, 2025 12:00
-
-
Save dpi0/737095cb09ce34f01070fc4242527203 to your computer and use it in GitHub Desktop.
zsh installation and set up on any debian/arch/fedora machine
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
#!/usr/bin/env bash | |
PKG="zsh" | |
SHELL_DIR="$HOME/sh" | |
CONFIG_FILE="$HOME/.zshrc" | |
P10K_DIR="$SHELL_DIR/zsh/powerlevel10k" | |
SHELL_REPO="https://github.com/dpi0/sh" | |
# Backup existing config | |
timestamped_backup() { | |
local target_file="$1" | |
if [ -f "$target_file" ]; then | |
local timestamp=$(date +"%d-%B-%Y_%H-%M-%S") | |
mv "$target_file" "${target_file}.old.$timestamp" | |
echo "Existing config backed up!" | |
fi | |
} | |
# Remove existing directories | |
cleanup_existing() { | |
[ -d "$SHELL_DIR" ] && rm -rf "$SHELL_DIR" | |
} | |
# Install package based on system type | |
install_pkg() { | |
if command -v apt &> /dev/null; then sudo apt install -y $PKG | |
elif command -v pacman &> /dev/null; then sudo pacman -Syu --noconfirm $PKG | |
elif command -v dnf &> /dev/null; then sudo dnf install -y $PKG | |
else echo "Unsupported system. Install manually..." | |
fi | |
} | |
# Ensure required dependencies are installed | |
curl -fsSL bin.dpi0.cloud/git | sh | |
if ! command -v $PKG &> /dev/null; then | |
echo "$PKG not found. Installing..." | |
install_pkg | |
else | |
echo "$PKG is already installed." | |
fi | |
download_repos() { | |
git clone --depth 1 "$SHELL_REPO" "$SHELL_DIR" | |
} | |
# Create symlink for .zshrc | |
symlink_config() { | |
ln -sf "$SHELL_DIR/zsh/.zshrc" "$CONFIG_FILE" | |
} | |
timestamped_backup "$CONFIG_FILE" | |
cleanup_existing | |
download_repos | |
symlink_config | |
echo "$PKG installation and setup complete. 🎉" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment