Skip to content

Instantly share code, notes, and snippets.

@theendofline
Created July 17, 2025 06:31
Show Gist options
  • Select an option

  • Save theendofline/9d159c1b433da5d92bbe510f436d4afd to your computer and use it in GitHub Desktop.

Select an option

Save theendofline/9d159c1b433da5d92bbe510f436d4afd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# install-zsh-stack.sh — bootstrap git, zsh, Oh-My-Zsh and five plugins
set -euo pipefail
##############################################################################
# 0. Set theme
##############################################################################
THEME="${THEME:-bira}"
echo "# → Theme to install: $THEME"
##############################################################################
# 1. Detect package manager and refresh the box
##############################################################################
if command -v apt-get >/dev/null; then
sudo apt-get update -y
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
INSTALL="sudo apt-get install -y"
elif command -v dnf >/dev/null; then
sudo dnf -y update
INSTALL="sudo dnf -y install"
elif command -v yum >/dev/null; then
sudo yum -y update
# Amazon Linux needs chsh → util-linux-user
sudo yum -y install util-linux-user
INSTALL="sudo yum -y install"
else
echo "❌ Unsupported Linux distribution"; exit 1
fi
$INSTALL git zsh curl
##############################################################################
# 2. Install Oh-My-Zsh unattended
##############################################################################
export RUNZSH=no CHSH=no KEEP_ZSHRC=yes
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh \
| sh -s -- --unattended #
##############################################################################
# 3. Clone plugins
##############################################################################
ZSH_DIR="$HOME/.oh-my-zsh"
CUSTOM_DIR="${ZSH_CUSTOM:-$ZSH_DIR/custom}"
declare -A REPO=(
[zsh-autosuggestions]=https://github.com/zsh-users/zsh-autosuggestions
[zsh-syntax-highlighting]=https://github.com/zsh-users/zsh-syntax-highlighting
[fast-syntax-highlighting]=https://github.com/zdharma-continuum/fast-syntax-highlighting
[zsh-autocomplete]=https://github.com/marlonrichert/zsh-autocomplete
)
for name in "${!REPO[@]}"; do
[[ -d "$CUSTOM_DIR/plugins/$name" ]] || \
git clone --depth=1 "${REPO[$name]}" "$CUSTOM_DIR/plugins/$name"
done
##############################################################################
# 4. Add custom theme
##############################################################################
if grep -q '^ZSH_THEME=' ~/.zshrc 2>/dev/null; then
sed -i "s/^ZSH_THEME=.*/ZSH_THEME=\"$THEME\"/" ~/.zshrc
else
# insert as first config line so it’s read before OMZ initialisation block
sed -i "1i ZSH_THEME=\"$THEME\"" ~/.zshrc
fi
##############################################################################
# 5. Write the plugin list in the *correct* order
##############################################################################
ORDERED_PLUGINS=(git zsh-autosuggestions zsh-syntax-highlighting \
fast-syntax-highlighting zsh-autocomplete)
# If .zshrc already has a plugins= line, replace it; else append one
if grep -q '^plugins=' ~/.zshrc 2>/dev/null; then
sed -i "s/^plugins=.*/plugins=(${ORDERED_PLUGINS[*]})/" ~/.zshrc
else
printf '\nplugins=(%s)\n' "${ORDERED_PLUGINS[*]}" >> ~/.zshrc
fi
# This order is the one recommended by users and maintainers
##############################################################################
# 5. Make zsh the default login shell
##############################################################################
ZSH_PATH=$(command -v zsh)
grep -qxF "$ZSH_PATH" /etc/shells || echo "$ZSH_PATH" | sudo tee -a /etc/shells
sudo chsh -s "$ZSH_PATH" "$USER"
echo -e "\n✅ Finished. Open a new terminal and you’ll drop into z s h with the desired plugin order and theme."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment