-
-
Save adamori/1f1793bf370245cf9d9f60918bfa23bf to your computer and use it in GitHub Desktop.
Setups oh-my-zsh with zsh-autosuggestions and zsh-syntax-highlighting plugins
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 | |
# Function to check if a command exists | |
command_exists() { | |
command -v "$1" >/dev/null 2>&1 | |
} | |
# Function to log messages | |
log() { | |
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | |
} | |
# Check for required package manager | |
if command_exists apt-get; then | |
PKG_MANAGER="apt-get" | |
INSTALL_CMD="apt-get install -y" | |
elif command_exists yum; then | |
PKG_MANAGER="yum" | |
INSTALL_CMD="yum install -y" | |
elif command_exists dnf; then | |
PKG_MANAGER="dnf" | |
INSTALL_CMD="dnf install -y" | |
elif command_exists pacman; then | |
PKG_MANAGER="pacman" | |
INSTALL_CMD="pacman -S --noconfirm" | |
else | |
log "Error: No supported package manager found" | |
exit 1 | |
fi | |
# Update package manager | |
log "Updating package manager..." | |
sudo $PKG_MANAGER update | |
# Install zsh if not already installed | |
if ! command_exists zsh; then | |
log "Installing zsh..." | |
sudo $INSTALL_CMD zsh | |
else | |
log "zsh is already installed" | |
fi | |
# Install git if not already installed (required for Oh My Zsh) | |
if ! command_exists git; then | |
log "Installing git..." | |
sudo $INSTALL_CMD git | |
else | |
log "git is already installed" | |
fi | |
# Install curl if not already installed | |
if ! command_exists curl; then | |
log "Installing curl..." | |
sudo $INSTALL_CMD curl | |
else | |
log "curl is already installed" | |
fi | |
# Install Oh My Zsh if not already installed | |
if [ ! -d "$HOME/.oh-my-zsh" ]; then | |
log "Installing Oh My Zsh..." | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended | |
else | |
log "Oh My Zsh is already installed" | |
fi | |
# Create custom plugins directory if it doesn't exist | |
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}" | |
mkdir -p "$ZSH_CUSTOM/plugins" | |
# Install zsh-autosuggestions | |
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]; then | |
log "Installing zsh-autosuggestions..." | |
git clone https://github.com/zsh-users/zsh-autosuggestions.git "$ZSH_CUSTOM/plugins/zsh-autosuggestions" | |
else | |
log "zsh-autosuggestions is already installed" | |
fi | |
# Install zsh-syntax-highlighting | |
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]; then | |
log "Installing zsh-syntax-highlighting..." | |
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" | |
else | |
log "zsh-syntax-highlighting is already installed" | |
fi | |
# Update .zshrc to include the plugins | |
ZSHRC="$HOME/.zshrc" | |
if [ -f "$ZSHRC" ]; then | |
# Backup existing .zshrc | |
cp "$ZSHRC" "$ZSHRC.backup.$(date +%Y%m%d_%H%M%S)" | |
# Update plugins line | |
if grep -q "^plugins=" "$ZSHRC"; then | |
log "Updating existing plugins line in .zshrc..." | |
sed -i 's/^plugins=(.*)$/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' "$ZSHRC" | |
else | |
log "Adding plugins line to .zshrc..." | |
echo 'plugins=(git zsh-autosuggestions zsh-syntax-highlighting)' >> "$ZSHRC" | |
fi | |
else | |
log "Creating new .zshrc..." | |
echo 'plugins=(git zsh-autosuggestions zsh-syntax-highlighting)' > "$ZSHRC" | |
fi | |
# Set ZSH as default shell if it isn't already | |
if [ "$SHELL" != "$(which zsh)" ]; then | |
log "Setting zsh as default shell..." | |
chsh -s "$(which zsh)" | |
fi | |
log "Installation complete! Please restart your terminal or run 'source ~/.zshrc'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment