mirror of
https://github.com/sortedcord/bootstrap.git
synced 2026-07-22 20:22:50 +05:30
refactor: Linting fixes
This commit is contained in:
8
b.sh
8
b.sh
@@ -1,3 +1,4 @@
|
||||
# shellcheck shell=bash
|
||||
# >>> bootstrap-cli b function >>>
|
||||
# Shortcut for downloading and running bootstrap/install scripts
|
||||
b() {
|
||||
@@ -19,6 +20,7 @@ b() {
|
||||
_version_lt() {
|
||||
[ "$1" = "$2" ] && return 1
|
||||
local IFS=.
|
||||
# shellcheck disable=SC2206
|
||||
local i ver1=($1) ver2=($2)
|
||||
for ((i=${#ver1[@]}; i<3; i++)); do ver1[i]=0; done
|
||||
for ((i=${#ver2[@]}; i<3; i++)); do ver2[i]=0; done
|
||||
@@ -41,7 +43,7 @@ b() {
|
||||
|
||||
local base_url="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master"
|
||||
local local_ver="0.0.0"
|
||||
[ -f "$routes_dir/VERSION" ] && local_ver=$(cat "$routes_dir/VERSION" 2>/dev/null | tr -d '[:space:]')
|
||||
[ -f "$routes_dir/VERSION" ] && local_ver=$(tr -d '[:space:]' < "$routes_dir/VERSION" 2>/dev/null)
|
||||
|
||||
local remote_ver
|
||||
if remote_ver=$(curl -fsSL "$base_url/VERSION" 2>/dev/null); then
|
||||
@@ -71,6 +73,7 @@ b() {
|
||||
# Sourced again in the parent shell after successfully running the command
|
||||
if [ $ret -eq 0 ]; then
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
fi
|
||||
@@ -123,6 +126,7 @@ _b_completion() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
|
||||
return 0
|
||||
fi
|
||||
@@ -161,6 +165,7 @@ _b_completion() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=( $(compgen -W "$installer_keys" -- "$cur") )
|
||||
return 0
|
||||
fi
|
||||
@@ -170,6 +175,7 @@ _b_completion() {
|
||||
# List of directories in ~/.config/ to choose from
|
||||
local config_dirs
|
||||
config_dirs=$(find "$HOME/.config" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; 2>/dev/null)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=( $(compgen -W "$config_dirs" -- "$cur") )
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -20,7 +20,7 @@ fi
|
||||
|
||||
# Locate or download libraries so that sourced installers can use them
|
||||
BOOTSTRAP_DIR="${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}"
|
||||
_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null || pwd)"
|
||||
_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd 2>/dev/null)" || _SCRIPT_DIR="$(pwd)"
|
||||
|
||||
if [ -f "$_SCRIPT_DIR/lib/common.sh" ]; then
|
||||
# Dev/local mode: source directly from repo
|
||||
@@ -268,7 +268,7 @@ EOF
|
||||
# Display centered version of bootstrap in bold
|
||||
_version=""
|
||||
if [ -f "$_version_file" ]; then
|
||||
_version=$(cat "$_version_file" | tr -d '\r\n')
|
||||
_version=$(tr -d '\r\n' < "$_version_file")
|
||||
fi
|
||||
if [ -z "$_version" ]; then
|
||||
_version="0.0.0" # Fallback if VERSION missing
|
||||
@@ -335,6 +335,7 @@ EOF
|
||||
|
||||
# Load the b function immediately in the current subshell
|
||||
if [ -f "$HOME/.config/bootstrap/b.sh" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$HOME/.config/bootstrap/b.sh"
|
||||
fi
|
||||
|
||||
@@ -347,6 +348,7 @@ else
|
||||
# Sourced mode (e.g., when sourced by installers or manually by user)
|
||||
# Load the b function in the current shell context
|
||||
if [ -f "$HOME/.config/bootstrap/b.sh" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$HOME/.config/bootstrap/b.sh"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# shellcheck shell=bash
|
||||
# Command: con
|
||||
# Edits configurations in ~/.config/
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# shellcheck shell=bash
|
||||
# Command: help
|
||||
# Lists all available bootstrap commands and installers
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# shellcheck shell=bash
|
||||
# Command: uninstall (gone)
|
||||
# Removes bootstrap CLI and cleans up shell configuration files
|
||||
|
||||
@@ -45,7 +46,6 @@ if [ -f "$HOME/.bash_aliases" ]; then
|
||||
|
||||
# 2. Remove specific aliases added by bootstrap (e.g. vim -> nvim)
|
||||
if grep -q '^alias vim="nvim"$' "$HOME/.bash_aliases" 2>/dev/null; then
|
||||
local tmp_file
|
||||
tmp_file=$(mktemp)
|
||||
sed '/^alias vim="nvim"$/d' "$HOME/.bash_aliases" > "$tmp_file"
|
||||
cat "$tmp_file" > "$HOME/.bash_aliases"
|
||||
@@ -61,7 +61,6 @@ fi
|
||||
|
||||
# If force is false, leave a lightweight 'b back' shortcut function in shell config files
|
||||
if [ "$FORCE" = "false" ]; then
|
||||
local b_back_content
|
||||
b_back_content=$(cat << 'EOF'
|
||||
b() {
|
||||
if [ "${1:-}" = "back" ]; then
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# shellcheck shell=bash
|
||||
# Command: up
|
||||
# Manually checks for updates and runs the updater if a newer version is found.
|
||||
|
||||
# Source libraries if needed
|
||||
if [ -z "${_LIB_COMMON_SOURCED:-}" ]; then
|
||||
_LIB_DIR="${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}/lib"
|
||||
# shellcheck source=/dev/null
|
||||
. "$_LIB_DIR/common.sh"
|
||||
fi
|
||||
|
||||
@@ -14,7 +16,7 @@ log_info "Checking for updates..."
|
||||
local_ver="0.0.0"
|
||||
version_file="${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}/VERSION"
|
||||
if [ -f "$version_file" ]; then
|
||||
local_ver=$(cat "$version_file" | tr -d '[:space:]')
|
||||
local_ver=$(tr -d '[:space:]' < "$version_file")
|
||||
fi
|
||||
|
||||
base_url="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master"
|
||||
|
||||
@@ -34,7 +34,8 @@ install_lazygit() {
|
||||
|
||||
local version="${latest_tag#v}"
|
||||
|
||||
local arch=$(detect_arch)
|
||||
local arch
|
||||
arch=$(detect_arch)
|
||||
local arch_str="x86_64"
|
||||
if [ "$arch" = "arm64" ]; then
|
||||
arch_str="arm64"
|
||||
|
||||
@@ -69,6 +69,7 @@ install_node() {
|
||||
if [ -s "$BOOTSTRAP_RUNTIMES/nvm/nvm.sh" ]; then
|
||||
# Temporarily disable nounset as nvm.sh does not support set -u
|
||||
set +u
|
||||
# shellcheck source=/dev/null
|
||||
. "$BOOTSTRAP_RUNTIMES/nvm/nvm.sh"
|
||||
else
|
||||
log_error "Could not load NVM to install Node.js."
|
||||
@@ -97,7 +98,7 @@ main() {
|
||||
if has_command node; then
|
||||
log_success "Node.js (via NVM) installation and configuration complete."
|
||||
log_info "Installed Node version: $(node --version)"
|
||||
log_info "Installed NVM version: $(nvm --version 2>/dev/null || cat "$BOOTSTRAP_RUNTIMES/nvm/package.json" | grep '"version":' | head -n1 | sed -E 's/.*"version": "([^"]+)".*/\1/' || echo "unknown")"
|
||||
log_info "Installed NVM version: $(nvm --version 2>/dev/null || grep '"version":' "$BOOTSTRAP_RUNTIMES/nvm/package.json" | head -n1 | sed -E 's/.*"version": "([^"]+)".*/\1/' || echo "unknown")"
|
||||
else
|
||||
log_success "Installation complete."
|
||||
fi
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
# Tool: nvim
|
||||
# DisplayName: Neovim
|
||||
# Description: Install Neovim 0.12.0 and configuration
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
# Tool: rust
|
||||
# DisplayName: Rust
|
||||
# Description: Install Rustup and Rust compiler/toolchain
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
# Tool: starship
|
||||
# DisplayName: Starship
|
||||
# Description: Install Starship shell prompt
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
# Tool: uv
|
||||
# DisplayName: uv
|
||||
# Description: Fast Python package installer and resolver
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
# Tool: zoxide
|
||||
# DisplayName: Zoxide
|
||||
# Description: Install Zoxide directory jumper
|
||||
|
||||
@@ -81,6 +81,7 @@ make_temp_dir() {
|
||||
version_lt() {
|
||||
[ "$1" = "$2" ] && return 1
|
||||
local IFS=.
|
||||
# shellcheck disable=SC2206
|
||||
local i ver1=($1) ver2=($2)
|
||||
for ((i=${#ver1[@]}; i<3; i++)); do ver1[i]=0; done
|
||||
for ((i=${#ver2[@]}; i<3; i++)); do ver2[i]=0; done
|
||||
|
||||
@@ -11,6 +11,7 @@ if [ -z "${_LIB_COMMON_SOURCED:-}" ]; then
|
||||
# Assumes common.sh is in the same directory as platform.sh
|
||||
# We resolve the directory of the current script
|
||||
_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=/dev/null
|
||||
. "$_LIB_DIR/common.sh"
|
||||
fi
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ EOF
|
||||
|
||||
for temp_file in "${temp_manifests[@]}"; do
|
||||
if [ -s "$temp_file" ]; then
|
||||
cat "$temp_file" | parse_plugin_manifest >> "$cache_file"
|
||||
parse_plugin_manifest < "$temp_file" >> "$cache_file"
|
||||
fi
|
||||
rm -f "$temp_file"
|
||||
done
|
||||
@@ -131,7 +131,7 @@ run_plugin() {
|
||||
if [ -n "$compat_ver" ]; then
|
||||
local current_ver="0.0.0"
|
||||
if [ -f "$BOOTSTRAP_DIR/VERSION" ]; then
|
||||
current_ver=$(cat "$BOOTSTRAP_DIR/VERSION" | tr -d '[:space:]')
|
||||
current_ver=$(tr -d '[:space:]' < "$BOOTSTRAP_DIR/VERSION")
|
||||
fi
|
||||
if version_lt "$compat_ver" "$current_ver"; then
|
||||
log_warn "Plugin '$plugin_name' is only tested up to bootstrap version $compat_ver (current: $current_ver). It may be incompatible."
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2034
|
||||
# This file is auto-generated by scripts/generate_registry.sh. Do not edit manually.
|
||||
|
||||
declare -A INSTALLERS=(
|
||||
|
||||
@@ -262,7 +262,7 @@ for script in "${SCRIPTS[@]}"; do
|
||||
fi
|
||||
;;
|
||||
fall)
|
||||
local savepoint_name="${1:-}"
|
||||
savepoint_name="${1:-}"
|
||||
if [ -z "$savepoint_name" ]; then
|
||||
log_error "Usage: b fall <savepoint_name>"
|
||||
exit 1
|
||||
@@ -271,7 +271,7 @@ for script in "${SCRIPTS[@]}"; do
|
||||
exit 0
|
||||
;;
|
||||
rb)
|
||||
local target="${1:-}"
|
||||
target="${1:-}"
|
||||
if [ -z "$target" ]; then
|
||||
rollback_bare
|
||||
else
|
||||
@@ -283,7 +283,7 @@ for script in "${SCRIPTS[@]}"; do
|
||||
uninstall_tool "$t"
|
||||
done
|
||||
else
|
||||
local registry_file="$BOOTSTRAP_STATE_DIR/registry.json"
|
||||
registry_file="$BOOTSTRAP_STATE_DIR/registry.json"
|
||||
if [ -f "$registry_file" ] && jq -e --arg t "$target" '.tools | has($t)' "$registry_file" >/dev/null; then
|
||||
uninstall_tool "$target"
|
||||
else
|
||||
|
||||
@@ -9,6 +9,7 @@ _LIB_SHELL_CONFIG_SOURCED=1
|
||||
# Source common utilities if not already loaded
|
||||
if [ -z "${_LIB_COMMON_SOURCED:-}" ]; then
|
||||
_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=/dev/null
|
||||
. "$_LIB_DIR/common.sh"
|
||||
fi
|
||||
|
||||
@@ -170,6 +171,7 @@ create_fd_symlink() {
|
||||
source_bashrc() {
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
log_info "Re-sourcing ~/.bashrc..."
|
||||
# shellcheck source=/dev/null
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ main() {
|
||||
log_success "Removed task #$task_num."
|
||||
;;
|
||||
clear)
|
||||
> "$TODO_FILE"
|
||||
true > "$TODO_FILE"
|
||||
log_success "Cleared all tasks from your todo list."
|
||||
;;
|
||||
--help|-h)
|
||||
|
||||
@@ -32,29 +32,31 @@ for f in "$INSTALLERS_DIR"/install_*.sh; do
|
||||
done
|
||||
|
||||
# Sort keys alphabetically
|
||||
sorted_keys=($(printf '%s\n' "${keys[@]}" | sort))
|
||||
mapfile -t sorted_keys < <(printf '%s\n' "${keys[@]}" | sort)
|
||||
|
||||
{
|
||||
echo "# shellcheck shell=bash"
|
||||
echo "# shellcheck disable=SC2034"
|
||||
echo "# This file is auto-generated by scripts/generate_registry.sh. Do not edit manually."
|
||||
echo ""
|
||||
echo "declare -A INSTALLERS=("
|
||||
for k in "${sorted_keys[@]}"; do
|
||||
# Escape any double quotes in description
|
||||
escaped_desc=$(echo "${tools_desc[$k]}" | sed 's/"/\\"/g')
|
||||
escaped_desc="${tools_desc[$k]//\"/\\\"}"
|
||||
echo " [$k]=\"$escaped_desc\""
|
||||
done
|
||||
echo ")"
|
||||
echo ""
|
||||
echo "declare -A INSTALLER_DISPLAYS=("
|
||||
for k in "${sorted_keys[@]}"; do
|
||||
escaped_disp=$(echo "${tools_disp[$k]}" | sed 's/"/\\"/g')
|
||||
escaped_disp="${tools_disp[$k]//\"/\\\"}"
|
||||
echo " [$k]=\"$escaped_disp\""
|
||||
done
|
||||
echo ")"
|
||||
echo ""
|
||||
echo "declare -A INSTALLER_STRATEGIES=("
|
||||
for k in "${sorted_keys[@]}"; do
|
||||
escaped_strat=$(echo "${tools_strat[$k]}" | sed 's/"/\\"/g')
|
||||
escaped_strat="${tools_strat[$k]//\"/\\\"}"
|
||||
echo " [$k]=\"$escaped_strat\""
|
||||
done
|
||||
echo ")"
|
||||
|
||||
Reference in New Issue
Block a user