Last active
November 23, 2025 19:33
-
-
Save codyzu/552372e4a9331c9109915ee53bafe908 to your computer and use it in GitHub Desktop.
Setup dev shell on several linux distros
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 | |
| set -euo pipefail | |
| need() { command -v "$1" >/dev/null 2>&1; } | |
| # Run a command as root: use sudo if needed, or run directly if already root | |
| as_root() { | |
| if [ "${EUID:-$(id -u)}" -eq 0 ]; then | |
| "$@" | |
| elif need sudo; then | |
| sudo "$@" | |
| else | |
| echo "⚠️ Need to run as root or have sudo installed to execute: $*" >&2 | |
| exit 1 | |
| fi | |
| } | |
| install_pkgs() { | |
| echo "📦 Installing base packages..." | |
| if need apt-get; then | |
| as_root apt-get update -y | |
| as_root apt-get install -y zsh git curl bat lsd nano || true | |
| # Debian/Ubuntu sometimes only ship batcat | |
| if ! need bat && need batcat; then | |
| as_root update-alternatives --install /usr/bin/bat bat /usr/bin/batcat 10 || true | |
| fi | |
| elif need dnf; then | |
| as_root dnf install -y zsh git curl bat lsd nano | |
| elif need yum; then | |
| as_root yum install -y zsh git curl bat lsd nano | |
| elif need pacman; then | |
| as_root pacman -Sy --noconfirm zsh git curl bat lsd nano | |
| elif need apk; then | |
| as_root apk add --no-cache zsh git curl bat lsd nano | |
| elif need zypper; then | |
| as_root zypper --non-interactive install zsh git curl bat lsd nano | |
| else | |
| echo "⚠️ No supported package manager found. Install zsh git curl bat lsd nano manually, then rerun." | |
| exit 1 | |
| fi | |
| } | |
| install_pkgs | |
| echo "✨ Installing Starship..." | |
| need starship || curl -sS https://starship.rs/install.sh | sh -s -- -y | |
| echo "🧠 Installing Atuin..." | |
| need atuin || curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh | bash | |
| # Configure Atuin defaults | |
| echo "🛠 Setting Atuin defaults..." | |
| mkdir -p "$HOME/.config/atuin" | |
| # idempotently set enter_accept = false | |
| if grep -q "^enter_accept" "$HOME/.config/atuin/config.toml" 2>/dev/null; then | |
| # update existing line | |
| sed -i.bak 's/^enter_accept.*/enter_accept = false/' "$HOME/.config/atuin/config.toml" | |
| else | |
| # append setting | |
| echo 'enter_accept = false' >> "$HOME/.config/atuin/config.toml" | |
| fi | |
| ZSHRC="$HOME/.zshrc" | |
| S="# >>> minimal-dev-shell start >>>" | |
| E="# <<< minimal-dev-shell end <<<" | |
| # remove existing managed block if present | |
| [ -f "$ZSHRC" ] && grep -qF "$S" "$ZSHRC" && sed -i.bak "/$S/,/$E/d" "$ZSHRC" | |
| touch "$ZSHRC" | |
| BAT_BIN=$( | |
| if need bat; then | |
| echo bat | |
| elif need batcat; then | |
| echo batcat | |
| else | |
| echo cat | |
| fi | |
| ) | |
| LSD_BIN=$( | |
| if need lsd; then | |
| echo lsd | |
| else | |
| echo "ls --color=auto" | |
| fi | |
| ) | |
| cat >>"$ZSHRC" <<EOF | |
| $S | |
| # Minimal dev shell setup - safe to re-run | |
| eval "\$(starship init zsh)" | |
| eval "\$(atuin init zsh)" | |
| alias cat='${BAT_BIN} --paging=never' | |
| alias ls='${LSD_BIN}' | |
| alias ll='ls -lh' | |
| alias la='ls -lha' | |
| # Automatically list directory contents on cd (interactive shells only) | |
| chpwd() { | |
| [[ \$- == *i* ]] || return | |
| [[ -t 1 ]] || return | |
| [[ -n "\$LS_DISABLE" ]] && return | |
| if command -v lsd >/dev/null 2>&1; then | |
| lsd -lha 2>/dev/null || ls -lha | |
| else | |
| ls -lha | |
| fi | |
| } | |
| setopt AUTO_CD | |
| setopt AUTO_PUSHD | |
| setopt PUSHD_IGNORE_DUPS | |
| $E | |
| EOF | |
| chmod 600 "$ZSHRC" || true | |
| # Only try to chsh when not root and when chsh exists | |
| if [ "${EUID:-$(id -u)}" -ne 0 ] && need chsh; then | |
| if [ "${SHELL:-}" != "$(command -v zsh)" ]; then | |
| echo "🔧 Setting default shell to zsh..." | |
| as_root chsh -s "$(command -v zsh)" "$(id -un)" | |
| fi | |
| else | |
| echo "ℹ️ Skipping chsh (running as root or chsh not available). You can start zsh with: zsh" | |
| fi | |
| echo | |
| echo "✅ Done! Open a new terminal or run: exec zsh" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run on a fresh install with:
wget -qO- https://gist.githubusercontent.com/codyzu/552372e4a9331c9109915ee53bafe908/raw/setup-dev-shell.sh | bash