commit 381f4c263cf66abf8a46f2d4f0bf002ac2ec128e Author: apt Date: Fri Aug 8 19:23:16 2025 +0100 Initial commit first version diff --git a/fish_installer.sh b/fish_installer.sh new file mode 100644 index 0000000..a72c187 --- /dev/null +++ b/fish_installer.sh @@ -0,0 +1,164 @@ +#!/bin/bash + +set -e + +# 🔍 Detect OS and Package Manager +detect_platform() { + if [[ "$OSTYPE" == "darwin"* ]]; then + OS="macos" + if ! command -v brew &>/dev/null; then + echo "🍺 Homebrew not found. Install it now? (y/N): " + read -r confirm + if [[ "$confirm" =~ ^[Yy]$ ]]; then + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile + eval "$(/opt/homebrew/bin/brew shellenv)" + else + echo "❌ Homebrew is required to install Fish on macOS. Exiting." + exit 1 + fi + fi + PKG_MGR="brew" + elif command -v apt &>/dev/null; then + OS="debian" + PKG_MGR="apt" + elif command -v dnf &>/dev/null; then + OS="rhel" + PKG_MGR="dnf" + elif command -v yum &>/dev/null; then + OS="rhel" + PKG_MGR="yum" + elif command -v pacman &>/dev/null; then + OS="arch" + PKG_MGR="pacman" + else + echo "❌ Unsupported platform." + exit 1 + fi +} + +# 🔐 Install gpg if not present (only for Debian) +install_gpg_if_needed() { + if [[ "$OS" == "debian" ]] && ! command -v gpg &>/dev/null; then + echo "🔑 gpg not found. Installing..." + sudo apt update && sudo apt install -y gnupg + fi +} + +# 📦 Add Fish shell repo for Debian/Ubuntu +add_fish_repo_debian() { + echo "Adding Fish shell repo for Debian/Ubuntu..." + echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/4/Debian_12/ /' | \ + sudo tee /etc/apt/sources.list.d/fish.list + curl -fsSL https://download.opensuse.org/repositories/shells:fish:release:4/Debian_12/Release.key | \ + gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/fish.gpg > /dev/null + sudo apt update +} + +# 🐟 Install Fish shell +install_fish() { + echo "🐟 Installing Fish shell for $OS..." + + case "$OS" in + debian) + add_fish_repo_debian + sudo apt install -y fish + ;; + rhel) + sudo $PKG_MGR install -y fish + ;; + arch) + sudo pacman -Sy --noconfirm fish + ;; + macos) + brew install fish + ;; + esac +} + +# ♻️ Check for updates to Fish shell +update_fish() { + echo "🔄 Checking for updates to Fish shell..." + case "$PKG_MGR" in + apt) + sudo apt update + if apt list --upgradable 2>/dev/null | grep -q "^fish/"; then + read -rp "An update is available. Update Fish? (y/N): " confirm + [[ "$confirm" =~ ^[Yy]$ ]] && sudo apt install -y fish + else + echo "✅ Fish is already up to date." + fi + ;; + dnf|yum) + sudo $PKG_MGR check-update || true + if $PKG_MGR list updates | grep -q "^fish"; then + read -rp "An update is available. Update Fish? (y/N): " confirm + [[ "$confirm" =~ ^[Yy]$ ]] && sudo $PKG_MGR update -y fish + else + echo "✅ Fish is already up to date." + fi + ;; + pacman) + sudo pacman -Sy --noconfirm + if pacman -Qu | grep -q "^fish"; then + read -rp "An update is available. Update Fish? (y/N): " confirm + [[ "$confirm" =~ ^[Yy]$ ]] && sudo pacman -S --noconfirm fish + else + echo "✅ Fish is already up to date." + fi + ;; + brew) + brew update + if brew outdated | grep -q "^fish"; then + read -rp "An update is available. Update Fish? (y/N): " confirm + [[ "$confirm" =~ ^[Yy]$ ]] && brew upgrade fish + else + echo "✅ Fish is already up to date." + fi + ;; + esac +} + +# 🎣 Install Fisher plugin manager +install_fisher() { + if [[ ! -d ~/.config/fish/functions ]]; then + mkdir -p ~/.config/fish/functions + fi + + echo "🎣 Installing Fisher plugin manager..." + fish -c 'curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher' +} + +# 🧩 Install recommended plugins +install_fish_plugins() { + echo "🧩 Installing Fish plugins..." + fish -c " + fisher install jorgebucaran/fisher + fisher install jethrokuan/z + fisher install ilancosman/tide + fisher install jorgebucaran/nvm.fish + " +} + +# 🏁 Main script +detect_platform +install_gpg_if_needed + +if command -v fish &>/dev/null; then + echo "✅ Fish shell is already installed." + update_fish +else + install_fish +fi + +# Ask if user wants to install Fisher and plugins +read -rp "Do you want to install Fisher plugin manager and some plugins? (y/N): " install_plugins +if [[ "$install_plugins" =~ ^[Yy]$ ]]; then + install_fisher + install_fish_plugins + echo "🎉 Fisher and plugins installed!" +else + echo "👍 Skipping plugin installation." +fi + +echo "✅ Fish shell setup complete on $OS!"