diff --git a/installers/install_bat.sh b/installers/install_bat.sh new file mode 100644 index 0000000..bc154da --- /dev/null +++ b/installers/install_bat.sh @@ -0,0 +1,155 @@ +#!/usr/bin/env bash +# +# Bat Installer Script +# + +# Run metascript to check if the shell is bash and load libraries +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 + +TMP_DIR="$(make_temp_dir)" +cleanup() { + rm -rf "$TMP_DIR" +} +trap cleanup EXIT + +install_bat() { + local distro + distro=$(detect_distro) + + if [ "$distro" = "arch" ]; then + log_info "Arch Linux detected" + if has_command bat; then + if ! confirm "Bat is already installed. Reinstall/Upgrade?"; then + log_info "Skipping Bat installation." + return + fi + else + if ! confirm "Install Bat?"; then + log_info "Skipping Bat installation." + return + fi + fi + + log_info "Installing Bat..." + pkg_install bat + + elif [ "$distro" = "fedora" ]; then + log_info "Fedora detected" + if has_command bat; then + if ! confirm "Bat is already installed. Reinstall/Upgrade?"; then + log_info "Skipping Bat installation." + return + fi + else + if ! confirm "Install Bat?"; then + log_info "Skipping Bat installation." + return + fi + fi + + log_info "Installing Bat..." + pkg_install bat + + elif [ "$distro" = "debian" ]; then + log_info "Debian/Ubuntu detected" + if has_command bat; then + if ! confirm "Bat is already installed. Reinstall/Upgrade?"; then + log_info "Skipping Bat installation." + return + fi + else + if ! confirm "Install Bat?"; then + log_info "Skipping Bat installation." + return + fi + fi + + pkg_install curl wget + + log_info "Fetching latest Bat version from GitHub..." + local latest_tag="" + if has_command curl; then + latest_tag=$(curl -sL https://api.github.com/repos/sharkdp/bat/releases/latest | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name": "([^"]+)".*/\1/' || true) + elif has_command wget; then + latest_tag=$(wget -qO- https://api.github.com/repos/sharkdp/bat/releases/latest | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name": "([^"]+)".*/\1/' || true) + fi + + if [ -z "$latest_tag" ]; then + latest_tag="v0.26.1" + log_warn "Failed to fetch latest version from GitHub. Falling back to: $latest_tag" + else + log_info "Latest Bat version found: $latest_tag" + fi + + # Remove leading 'v' for file name version + local version="${latest_tag#v}" + + # Detect architecture mapping + local arch + arch=$(detect_arch) + local deb_arch="amd64" + if [ "$arch" = "arm64" ]; then + deb_arch="arm64" + fi + + local deb_url="https://github.com/sharkdp/bat/releases/download/${latest_tag}/bat_${version}_${deb_arch}.deb" + log_info "Downloading Bat from ${deb_url}..." + if has_command curl; then + curl -fsSL "$deb_url" -o "$TMP_DIR/bat.deb" + else + wget -qO "$TMP_DIR/bat.deb" "$deb_url" + fi + + log_info "Installing Bat package..." + sudo apt install -y "$TMP_DIR/bat.deb" + + else + log_error "Unsupported distribution." + exit 1 + fi +} + +configure_shell() { + IFS=' ' read -ra target_files <<< "$(get_shell_configs)" + + local content="alias cat='bat --paging=never'" + + for config_file in "${target_files[@]}"; do + log_info "Adding bat alias to $config_file..." + inject_block "$config_file" "bat alias" "$content" + + # Source if modified (only for bashrc) + if [ "$config_file" = "$HOME/.bashrc" ]; then + log_info "Sourcing $config_file..." + . "$config_file" 2>/dev/null || true + fi + done +} + +main() { + install_bat + configure_shell + + echo + log_success "Bat installation and configuration complete." + log_info "Please close and reopen your terminal or run: source ~/.bashrc (or source ~/.zshrc) to apply changes." +} + +main "$@" diff --git a/readme.md b/readme.md index 720df2e..c77911c 100644 --- a/readme.md +++ b/readme.md @@ -9,6 +9,7 @@ The goal is simple: reduce the number of manual steps required after installing | Script | Description | | ----------------- | --------------------------------------------------------------------- | | `install_agy.sh` | Installs Antigravity CLI and triggers native shell configuration. | +| `install_bat.sh` | Installs Bat (alternative to cat) and configures alias. | | `install_node.sh` | Installs Node.js (LTS) and NVM (Node Version Manager). | | `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. | diff --git a/routes.sh b/routes.sh index a1557af..03bbb4e 100755 --- a/routes.sh +++ b/routes.sh @@ -18,13 +18,14 @@ require_bash # Registry of installers declare -A INSTALLERS=( [agy]="Install Antigravity CLI" + [bat]="Install Bat (alternative to cat) and configure alias" [node]="Install Node.js (LTS) and NVM" [nvim]="Install Neovim 0.11.7 and configuration" [yazi]="Install Yazi terminal file manager and dependencies" [zoxide]="Install Zoxide directory jumper" ) # Order in which installers should be displayed -INSTALLER_KEYS=(agy node nvim yazi zoxide) +INSTALLER_KEYS=(agy bat node nvim yazi zoxide) SCRIPT_NAMES="${1:-}" if [ -z "$SCRIPT_NAMES" ] || [ "$SCRIPT_NAMES" = "-h" ] || [ "$SCRIPT_NAMES" = "--help" ]; then