major refactor
This commit is contained in:
@@ -2,18 +2,8 @@
|
||||
#
|
||||
# Neovim Installer Script
|
||||
#
|
||||
# What this script does:
|
||||
# 1. Detects the Linux distribution.
|
||||
# 2. Installs required dependencies (git, wget, tar, curl, unzip, ripgrep, fd, cmake, make, gcc, python, nodejs, npm, xclip, wl-clipboard, fzf).
|
||||
# 3. Checks whether Neovim 0.11.7 is already installed.
|
||||
# 4. Prompts before installing or upgrading Neovim.
|
||||
# 5. Installs the official Neovim binary to /opt/nvim.
|
||||
# 6. Creates a symlink at /usr/local/bin/nvim.
|
||||
# 7. Clones the Neovim configuration into ~/.config/nvim.
|
||||
# 8. Configures shell files (~/.bashrc / ~/.zshrc) to set alias vim="nvim" and export EDITOR="nvim".
|
||||
#
|
||||
|
||||
# Run metascript to check if the shell is bash
|
||||
# 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"
|
||||
@@ -33,33 +23,21 @@ fi
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
NVIM_VERSION="0.11.7"
|
||||
NVIM_URL="https://github.com/neovim/neovim/releases/download/v${NVIM_VERSION}/nvim-linux-x86_64.tar.gz"
|
||||
NVIM_INSTALL_DIR="/opt/nvim"
|
||||
NVIM_CONFIG_REPO="https://git.adityagupta.dev/sortedcord/editor.git"
|
||||
NVIM_CONFIG_DIR="$HOME/.config/nvim"
|
||||
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
|
||||
TMP_DIR="$(make_temp_dir)"
|
||||
cleanup() {
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
confirm() {
|
||||
local prompt="$1"
|
||||
local response
|
||||
|
||||
read -r -p "$prompt [y/N]: " response </dev/tty || true
|
||||
|
||||
[[ "$response" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
check_config_dir() {
|
||||
if [[ -d "$NVIM_CONFIG_DIR" ]]; then
|
||||
if confirm "$NVIM_CONFIG_DIR already exists. Replace it?"; then
|
||||
echo "Existing configuration will be removed during setup."
|
||||
log_info "Existing configuration will be removed during setup."
|
||||
rm -rf "$NVIM_CONFIG_DIR"
|
||||
else
|
||||
while true; do
|
||||
@@ -69,7 +47,7 @@ check_config_dir() {
|
||||
alt_dir="${alt_dir/#\~/$HOME}"
|
||||
|
||||
if [[ -z "$alt_dir" ]]; then
|
||||
echo "Directory path cannot be empty. Please try again."
|
||||
log_warn "Directory path cannot be empty. Please try again."
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -81,71 +59,74 @@ check_config_dir() {
|
||||
}
|
||||
|
||||
install_packages() {
|
||||
echo "Detecting distribution and installing dependencies..."
|
||||
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
echo "Arch Linux detected"
|
||||
sudo pacman -Sy --needed git wget tar curl unzip ripgrep fd cmake make gcc python nodejs npm xclip wl-clipboard fzf
|
||||
|
||||
elif command -v apt >/dev/null 2>&1; then
|
||||
echo "Debian/Ubuntu detected"
|
||||
sudo apt update
|
||||
sudo apt install -y git wget tar curl unzip ripgrep fd-find cmake build-essential python3 python3-pip python3-venv nodejs npm xclip wl-clipboard fzf
|
||||
log_info "Detecting distribution and installing dependencies..."
|
||||
pkg_install \
|
||||
git wget tar curl unzip ripgrep fzf nodejs npm xclip wl-clipboard \
|
||||
"arch:fd|debian:fd-find|fedora:fd-find" \
|
||||
"arch:cmake|debian:cmake|fedora:cmake" \
|
||||
"arch:make|debian:build-essential|fedora:make" \
|
||||
"arch:gcc|debian:build-essential|fedora:gcc" \
|
||||
"arch:python|debian:python3|fedora:python3" \
|
||||
"debian:python3-pip|fedora:python3-pip" \
|
||||
"debian:python3-venv" \
|
||||
"fedora:gcc-c++"
|
||||
|
||||
# Create a symlink for fd-find if it doesn't already exist as fd
|
||||
if ! command -v fd >/dev/null 2>&1 && command -v fdfind >/dev/null 2>&1; then
|
||||
echo "Creating symlink for fd..."
|
||||
sudo ln -sf "$(command -v fdfind)" /usr/local/bin/fd
|
||||
fi
|
||||
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
echo "Fedora detected"
|
||||
sudo dnf install -y git wget tar curl unzip ripgrep fd-find cmake make gcc gcc-c++ python3 python3-pip nodejs npm xclip wl-clipboard fzf
|
||||
|
||||
else
|
||||
echo "Unsupported distribution."
|
||||
exit 1
|
||||
fi
|
||||
create_fd_symlink
|
||||
}
|
||||
|
||||
install_nvim() {
|
||||
local current_version=""
|
||||
|
||||
if command -v nvim >/dev/null 2>&1; then
|
||||
if has_command nvim; then
|
||||
current_version="$(nvim --version | head -n1 | awk '{print $2}')"
|
||||
|
||||
if [[ "$current_version" == "v${NVIM_VERSION}" ]] || [[ "$current_version" == "${NVIM_VERSION}" ]]; then
|
||||
echo "Neovim ${current_version} already installed."
|
||||
log_info "Neovim ${current_version} already installed."
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Detected Neovim ${current_version}"
|
||||
log_info "Detected Neovim ${current_version}"
|
||||
|
||||
if ! confirm "Upgrade to Neovim v${NVIM_VERSION}?"; then
|
||||
echo "Skipping Neovim upgrade."
|
||||
log_info "Skipping Neovim upgrade."
|
||||
return
|
||||
fi
|
||||
else
|
||||
echo "Neovim not installed."
|
||||
log_info "Neovim not installed."
|
||||
|
||||
if ! confirm "Install Neovim v${NVIM_VERSION}?"; then
|
||||
echo "Skipping Neovim installation."
|
||||
log_info "Skipping Neovim installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Downloading Neovim v${NVIM_VERSION}..."
|
||||
# Detect architecture to resolve the release binary name (Fix 4)
|
||||
local arch
|
||||
arch=$(detect_arch)
|
||||
local nvim_arch=""
|
||||
case "$arch" in
|
||||
x86_64) nvim_arch="linux-x86_64" ;;
|
||||
arm64) nvim_arch="linux-arm64" ;;
|
||||
*) log_error "Unsupported architecture: $arch"; exit 1 ;;
|
||||
esac
|
||||
|
||||
wget -qO "$TMP_DIR/nvim.tar.gz" "$NVIM_URL"
|
||||
local nvim_url="https://github.com/neovim/neovim/releases/download/v${NVIM_VERSION}/nvim-${nvim_arch}.tar.gz"
|
||||
|
||||
log_info "Downloading Neovim v${NVIM_VERSION} for ${arch}..."
|
||||
if has_command curl; then
|
||||
curl -fsSL "$nvim_url" -o "$TMP_DIR/nvim.tar.gz"
|
||||
else
|
||||
wget -qO "$TMP_DIR/nvim.tar.gz" "$nvim_url"
|
||||
fi
|
||||
|
||||
tar -xzf "$TMP_DIR/nvim.tar.gz" -C "$TMP_DIR"
|
||||
|
||||
sudo rm -rf "$NVIM_INSTALL_DIR"
|
||||
sudo mv "$TMP_DIR/nvim-linux-x86_64" "$NVIM_INSTALL_DIR"
|
||||
sudo mv "$TMP_DIR/nvim-${nvim_arch}" "$NVIM_INSTALL_DIR"
|
||||
|
||||
sudo ln -sf "$NVIM_INSTALL_DIR/bin/nvim" /usr/local/bin/nvim
|
||||
|
||||
echo "Installed:"
|
||||
log_success "Installed:"
|
||||
nvim --version | head -n1
|
||||
}
|
||||
|
||||
@@ -158,34 +139,26 @@ install_config() {
|
||||
rm -rf "$NVIM_CONFIG_DIR"
|
||||
fi
|
||||
|
||||
echo "Cloning configuration to $NVIM_CONFIG_DIR..."
|
||||
log_info "Cloning configuration to $NVIM_CONFIG_DIR..."
|
||||
git clone "$NVIM_CONFIG_REPO" "$NVIM_CONFIG_DIR"
|
||||
echo "Configuration installed."
|
||||
log_success "Configuration installed."
|
||||
}
|
||||
|
||||
configure_shell() {
|
||||
local target_files=()
|
||||
[ -f "$HOME/.bashrc" ] && target_files+=("$HOME/.bashrc")
|
||||
[ -f "$HOME/.zshrc" ] && target_files+=("$HOME/.zshrc")
|
||||
IFS=' ' read -ra target_files <<< "$(get_shell_configs)"
|
||||
|
||||
for config_file in "${target_files[@]}"; do
|
||||
local modified=false
|
||||
|
||||
# Add alias vim=nvim if not present
|
||||
if ! grep -q "alias vim=" "$config_file" 2>/dev/null; then
|
||||
echo "Adding alias vim=nvim to $config_file..."
|
||||
echo 'alias vim="nvim"' >> "$config_file"
|
||||
if add_alias_if_missing "$config_file" "vim" "nvim"; then
|
||||
modified=true
|
||||
fi
|
||||
|
||||
# Add export EDITOR=nvim if not present
|
||||
if ! grep -q "export EDITOR=" "$config_file" 2>/dev/null; then
|
||||
echo "Setting EDITOR=nvim in $config_file..."
|
||||
echo 'export EDITOR="nvim"' >> "$config_file"
|
||||
if add_env_if_missing "$config_file" "EDITOR" "nvim"; then
|
||||
modified=true
|
||||
fi
|
||||
|
||||
# Source if modified
|
||||
# Source if modified (only for bashrc, and not when sourced to prevent recursion)
|
||||
if [ "$modified" = true ] && [ "$config_file" = "$HOME/.bashrc" ]; then
|
||||
. "$config_file" 2>/dev/null || true
|
||||
fi
|
||||
@@ -200,7 +173,7 @@ main() {
|
||||
configure_shell
|
||||
|
||||
echo
|
||||
echo "Installation complete."
|
||||
log_success "Installation complete."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -2,18 +2,8 @@
|
||||
#
|
||||
# Yazi Installer Script
|
||||
#
|
||||
# What this script does:
|
||||
# 1. Detects the Linux distribution.
|
||||
# 2. Prompts before installing or upgrading Yazi.
|
||||
# 3. Installs Yazi:
|
||||
# * Arch Linux: Installs yazi via pacman.
|
||||
# * Debian / Ubuntu: Downloads the latest .deb release package from GitHub and installs it.
|
||||
# * Fedora: Enables the COPR repository (lihaohong/yazi) and installs yazi (initially skipping weak dependencies).
|
||||
# 4. Subsequently installs the dependencies (ffmpeg, 7zip / p7zip-full, jq, poppler, fd / fd-find, ripgrep, fzf, zoxide, resvg, imagemagick) to make Yazi available quicker.
|
||||
# 5. Configures a shell wrapper function 'y' in ~/.bashrc and ~/.zshrc that allows changing directory on exit.
|
||||
#
|
||||
|
||||
# Run metascript to check if the shell is bash
|
||||
# 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"
|
||||
@@ -33,37 +23,17 @@ fi
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
|
||||
TMP_DIR="$(make_temp_dir)"
|
||||
cleanup() {
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
confirm() {
|
||||
local prompt="$1"
|
||||
local response
|
||||
|
||||
read -r -p "$prompt [y/N]: " response </dev/tty || true
|
||||
|
||||
[[ "$response" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
add_y_wrapper() {
|
||||
local target_files=()
|
||||
[ -f "$HOME/.bashrc" ] && target_files+=("$HOME/.bashrc")
|
||||
[ -f "$HOME/.zshrc" ] && target_files+=("$HOME/.zshrc")
|
||||
IFS=' ' read -ra target_files <<< "$(get_shell_configs)"
|
||||
|
||||
for config_file in "${target_files[@]}"; do
|
||||
# Clean up old versions if any exist
|
||||
if grep -q "# >>> yazi wrapper >>>" "$config_file" 2>/dev/null; then
|
||||
sed -i '/# >>> yazi wrapper >>>/,/# <<< yazi wrapper <<</d' "$config_file"
|
||||
fi
|
||||
|
||||
echo "Adding yazi wrapper function 'y' to $config_file..."
|
||||
cat << 'EOF' >> "$config_file"
|
||||
|
||||
# >>> yazi wrapper >>>
|
||||
local wrapper_content
|
||||
wrapper_content=$(cat << 'EOF'
|
||||
# Shell wrapper for yazi to change directory on exit
|
||||
y() {
|
||||
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
|
||||
@@ -73,108 +43,112 @@ y() {
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
# <<< yazi wrapper <<<
|
||||
EOF
|
||||
)
|
||||
|
||||
for config_file in "${target_files[@]}"; do
|
||||
log_info "Adding yazi wrapper function 'y' to $config_file..."
|
||||
inject_block "$config_file" "yazi wrapper" "$wrapper_content"
|
||||
done
|
||||
|
||||
# Source ~/.bashrc to make the alias immediately available in the current shell context (if sourced)
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
echo "Sourcing ~/.bashrc..."
|
||||
. "$HOME/.bashrc"
|
||||
log_info "Sourcing ~/.bashrc..."
|
||||
. "$HOME/.bashrc" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
install_yazi() {
|
||||
echo "Detecting distribution..."
|
||||
local distro
|
||||
distro=$(detect_distro)
|
||||
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
echo "Arch Linux detected"
|
||||
if command -v yazi >/dev/null 2>&1; then
|
||||
if [ "$distro" = "arch" ]; then
|
||||
log_info "Arch Linux detected"
|
||||
if has_command yazi; then
|
||||
if ! confirm "Yazi is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
log_info "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Yazi and its dependencies?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
log_info "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installing Yazi..."
|
||||
sudo pacman -Sy --needed yazi
|
||||
log_info "Installing Yazi..."
|
||||
pkg_install yazi
|
||||
log_info "Installing dependencies subsequently..."
|
||||
pkg_install ffmpeg 7zip jq poppler fd ripgrep fzf zoxide resvg imagemagick
|
||||
|
||||
echo "Installing dependencies subsequently..."
|
||||
sudo pacman -S --needed ffmpeg 7zip jq poppler fd ripgrep fzf zoxide resvg imagemagick
|
||||
|
||||
elif command -v apt >/dev/null 2>&1; then
|
||||
echo "Debian/Ubuntu detected"
|
||||
if command -v yazi >/dev/null 2>&1; then
|
||||
elif [ "$distro" = "debian" ]; then
|
||||
log_info "Debian/Ubuntu detected"
|
||||
if has_command yazi; then
|
||||
if ! confirm "Yazi is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
log_info "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Yazi and its dependencies?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
log_info "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo apt update
|
||||
sudo apt install -y curl wget git
|
||||
pkg_install curl wget git
|
||||
|
||||
echo "Fetching latest Yazi version from GitHub..."
|
||||
LATEST_TAG=$(curl -sL https://api.github.com/repos/sxyazi/yazi/releases/latest | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
LATEST_TAG="v26.5.6"
|
||||
log_info "Fetching latest Yazi version from GitHub..."
|
||||
local latest_tag
|
||||
latest_tag=$(curl -sL https://api.github.com/repos/sxyazi/yazi/releases/latest | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
|
||||
if [ -z "$latest_tag" ]; then
|
||||
latest_tag="v26.5.6"
|
||||
fi
|
||||
|
||||
DEB_URL="https://github.com/sxyazi/yazi/releases/download/${LATEST_TAG}/yazi-x86_64-unknown-linux-gnu.deb"
|
||||
echo "Downloading Yazi ${LATEST_TAG} from ${DEB_URL}..."
|
||||
wget -qO "$TMP_DIR/yazi.deb" "$DEB_URL"
|
||||
local deb_url="https://github.com/sxyazi/yazi/releases/download/${latest_tag}/yazi-x86_64-unknown-linux-gnu.deb"
|
||||
log_info "Downloading Yazi ${latest_tag} from ${deb_url}..."
|
||||
if has_command curl; then
|
||||
curl -fsSL "$deb_url" -o "$TMP_DIR/yazi.deb"
|
||||
else
|
||||
wget -qO "$TMP_DIR/yazi.deb" "$deb_url"
|
||||
fi
|
||||
|
||||
echo "Installing Yazi package..."
|
||||
log_info "Installing Yazi package..."
|
||||
sudo apt install -y "$TMP_DIR/yazi.deb"
|
||||
|
||||
echo "Installing dependencies subsequently..."
|
||||
sudo apt install -y ffmpeg jq poppler-utils fd-find ripgrep fzf zoxide resvg imagemagick 7zip || \
|
||||
sudo apt install -y ffmpeg jq poppler-utils fd-find ripgrep fzf zoxide resvg imagemagick p7zip-full
|
||||
log_info "Installing dependencies subsequently..."
|
||||
pkg_install ffmpeg jq poppler-utils fd-find ripgrep fzf zoxide resvg imagemagick 7zip || \
|
||||
pkg_install ffmpeg jq poppler-utils fd-find ripgrep fzf zoxide resvg imagemagick p7zip-full
|
||||
|
||||
# Create a symlink for fd-find if it doesn't already exist as fd
|
||||
if ! command -v fd >/dev/null 2>&1 && command -v fdfind >/dev/null 2>&1; then
|
||||
echo "Creating symlink for fd..."
|
||||
sudo ln -sf "$(command -v fdfind)" /usr/local/bin/fd
|
||||
fi
|
||||
create_fd_symlink
|
||||
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
echo "Fedora detected"
|
||||
if command -v yazi >/dev/null 2>&1; then
|
||||
elif [ "$distro" = "fedora" ]; then
|
||||
log_info "Fedora detected"
|
||||
if has_command yazi; then
|
||||
if ! confirm "Yazi is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
log_info "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Yazi and its dependencies?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
log_info "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installing dnf-plugins-core..."
|
||||
sudo dnf install -y dnf-plugins-core
|
||||
log_info "Installing dnf-plugins-core..."
|
||||
pkg_install dnf-plugins-core
|
||||
|
||||
echo "Enabling lihaohong/yazi copr repo..."
|
||||
log_info "Enabling lihaohong/yazi copr repo..."
|
||||
sudo dnf copr enable -y lihaohong/yazi
|
||||
|
||||
echo "Installing Yazi (without weak dependencies first)..."
|
||||
log_info "Installing Yazi (without weak dependencies first)..."
|
||||
sudo dnf install -y yazi --setopt=install_weak_deps=False
|
||||
|
||||
echo "Installing weak dependencies subsequently..."
|
||||
sudo dnf install -y yazi
|
||||
log_info "Installing weak dependencies subsequently..."
|
||||
pkg_install yazi
|
||||
|
||||
else
|
||||
echo "Unsupported distribution."
|
||||
log_error "Unsupported distribution."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -183,7 +157,7 @@ main() {
|
||||
install_yazi
|
||||
add_y_wrapper
|
||||
echo
|
||||
echo "Yazi installation and configuration complete."
|
||||
log_success "Yazi installation and configuration complete."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
@@ -2,16 +2,8 @@
|
||||
#
|
||||
# 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
|
||||
# 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"
|
||||
@@ -31,94 +23,61 @@ fi
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
confirm() {
|
||||
local prompt="$1"
|
||||
local response
|
||||
|
||||
read -r -p "$prompt [y/N]: " response </dev/tty || true
|
||||
|
||||
[[ "$response" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
install_curl() {
|
||||
if ! command -v curl >/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
|
||||
if ! has_command curl; then
|
||||
log_info "curl not found. Installing curl..."
|
||||
pkg_install curl
|
||||
fi
|
||||
}
|
||||
|
||||
install_fzf() {
|
||||
if command -v fzf >/dev/null 2>&1; then
|
||||
echo "fzf is already installed."
|
||||
if has_command fzf; then
|
||||
log_info "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
|
||||
log_info "fzf not found. Installing fzf..."
|
||||
pkg_install fzf
|
||||
}
|
||||
|
||||
install_zoxide() {
|
||||
if command -v zoxide >/dev/null 2>&1 || [ -f "$HOME/.local/bin/zoxide" ]; then
|
||||
if has_command zoxide || [ -f "$HOME/.local/bin/zoxide" ]; then
|
||||
if ! confirm "Zoxide is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Zoxide installation."
|
||||
log_info "Skipping Zoxide installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Zoxide?"; then
|
||||
echo "Skipping Zoxide installation."
|
||||
log_info "Skipping Zoxide installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
install_curl
|
||||
|
||||
echo "Downloading and running the official zoxide installer..."
|
||||
log_info "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 <<</d' "$config_file"
|
||||
fi
|
||||
IFS=' ' read -ra target_files <<< "$(get_shell_configs)"
|
||||
|
||||
for config_file in "${target_files[@]}"; do
|
||||
local shell_name="bash"
|
||||
if [[ "$config_file" == *".zshrc" ]]; then
|
||||
shell_name="zsh"
|
||||
fi
|
||||
|
||||
echo "Adding zoxide initialization to $config_file..."
|
||||
cat << EOF >> "$config_file"
|
||||
log_info "Adding zoxide initialization to $config_file..."
|
||||
local content
|
||||
content="eval \"\$(zoxide init --cmd cd $shell_name)\""
|
||||
|
||||
inject_block "$config_file" "zoxide init" "$content"
|
||||
|
||||
# >>> zoxide init >>>
|
||||
eval "\$(zoxide init --cmd cd $shell_name)"
|
||||
# <<< zoxide init <<<
|
||||
EOF
|
||||
# Source if modified (only for bashrc currently)
|
||||
# Source if modified (only for bashrc)
|
||||
if [ "$config_file" = "$HOME/.bashrc" ]; then
|
||||
. "$config_file" 2>/dev/null || true
|
||||
fi
|
||||
@@ -131,7 +90,7 @@ main() {
|
||||
install_fzf
|
||||
|
||||
echo
|
||||
echo "Zoxide installation and configuration complete."
|
||||
log_success "Zoxide installation and configuration complete."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user