diff --git a/installers/install_zoxide.sh b/installers/install_zoxide.sh new file mode 100755 index 0000000..1bff5d9 --- /dev/null +++ b/installers/install_zoxide.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash +# +# Zoxide Installer Script +# +# What this script does: +# 1. Detects the Linux distribution. +# 2. Checks whether zoxide is already installed. +# 3. Prompts before installing or upgrading zoxide. +# 4. Downloads and runs the official zoxide installer script. +# 5. Configures shell configuration files (~/.bashrc / ~/.zshrc) to initialize zoxide. +# 6. Checks if fzf is installed; if not, installs it using the system package manager. +# + +# Run metascript to check if the shell is bash +PARENT_DIR="$(dirname "$0")/.." +METASCRIPT_LOCAL="$PARENT_DIR/bootstrap.sh" +METASCRIPT_URL="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh" + +if [ -f "$METASCRIPT_LOCAL" ]; then + . "$METASCRIPT_LOCAL" +else + if command -v wget >/dev/null 2>&1; then + eval "$(wget -qO- "$METASCRIPT_URL")" + elif command -v curl >/dev/null 2>&1; then + eval "$(curl -fsSL "$METASCRIPT_URL")" + else + echo "Error: Neither wget nor curl is installed to fetch bootstrap.sh." >&2 + exit 1 + fi +fi + +set -euo pipefail + +confirm() { + local prompt="$1" + local response + + read -r -p "$prompt [y/N]: " response /dev/null 2>&1; then + echo "curl not found. Installing curl..." + if command -v pacman >/dev/null 2>&1; then + sudo pacman -Sy --needed curl + elif command -v apt >/dev/null 2>&1; then + sudo apt update + sudo apt install -y curl + elif command -v dnf >/dev/null 2>&1; then + sudo dnf install -y curl + fi + fi +} + +install_fzf() { + if command -v fzf >/dev/null 2>&1; then + echo "fzf is already installed." + return + fi + + echo "fzf not found. Installing fzf..." + if command -v pacman >/dev/null 2>&1; then + sudo pacman -Sy --needed fzf + elif command -v apt >/dev/null 2>&1; then + sudo apt update + sudo apt install -y fzf + elif command -v dnf >/dev/null 2>&1; then + sudo dnf install -y fzf + else + echo "Warning: Unsupported distribution. Please install fzf manually." >&2 + fi +} + +install_zoxide() { + if command -v zoxide >/dev/null 2>&1 || [ -f "$HOME/.local/bin/zoxide" ]; then + if ! confirm "Zoxide is already installed. Reinstall/Upgrade?"; then + echo "Skipping Zoxide installation." + return + fi + else + if ! confirm "Install Zoxide?"; then + echo "Skipping Zoxide installation." + return + fi + fi + + install_curl + + echo "Downloading and running the official zoxide installer..." + curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh +} + +configure_shell() { + local target_files=() + [ -f "$HOME/.bashrc" ] && target_files+=("$HOME/.bashrc") + [ -f "$HOME/.zshrc" ] && target_files+=("$HOME/.zshrc") + + # Add ~/.local/bin to PATH for the current process + export PATH="$HOME/.local/bin:$PATH" + + for config_file in "${target_files[@]}"; do + # Clean up old block if it exists + if grep -q "# >>> zoxide init >>>" "$config_file" 2>/dev/null; then + sed -i '/# >>> zoxide init >>>/,/# <<< zoxide init <<> "$config_file" + +# >>> zoxide init >>> +eval "\$(zoxide init --cmd cd $shell_name)" +# <<< zoxide init <<< +EOF + # Source if modified (only for bashrc currently) + if [ "$config_file" = "$HOME/.bashrc" ]; then + . "$config_file" 2>/dev/null || true + fi + done +} + +main() { + install_zoxide + configure_shell + install_fzf + + echo + echo "Zoxide installation and configuration complete." +} + +main "$@" diff --git a/readme.md b/readme.md index 9bff598..2e21a4c 100644 --- a/readme.md +++ b/readme.md @@ -10,6 +10,7 @@ The goal is simple: reduce the number of manual steps required after installing | ----------------- | --------------------------------------------------------------------- | | `install_nvim.sh` | Installs Neovim 0.11.7 and clones my Neovim configuration repository. | | `install_yazi.sh` | Installs Yazi terminal file manager and its dependencies. | +| `install_zoxide.sh` | Installs Zoxide directory jumper and configures shell integrations. | All scripts support Arch Linux, Debian / Ubuntu, and Fedora. diff --git a/routes.sh b/routes.sh index dcd6e26..e5a8f79 100755 --- a/routes.sh +++ b/routes.sh @@ -28,6 +28,10 @@ for script in "${SCRIPTS[@]}"; do echo "Launching Yazi installer..." curl -fsSL "https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/installers/install_yazi.sh" | bash -s -- "$@" ;; + zoxide) + echo "Launching Zoxide installer..." + curl -fsSL "https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/installers/install_zoxide.sh" | bash -s -- "$@" + ;; bye) echo "Removing bootstrap CLI completely..." @@ -53,7 +57,7 @@ for script in "${SCRIPTS[@]}"; do ;; *) echo "Error: Unknown script '$script'." >&2 - echo "Available scripts: nvim, yazi, bye" >&2 + echo "Available scripts: nvim, yazi, zoxide, bye" >&2 exit 1 ;; esac