major refactor

This commit is contained in:
2026-06-19 23:42:18 +05:30
parent a786af12c9
commit e9fbd08423
12 changed files with 621 additions and 356 deletions

43
commands/conf.sh Normal file
View File

@@ -0,0 +1,43 @@
# Command: conf
# Edits configurations in ~/.config/
config_name="${1:-}"
if [ -z "$config_name" ]; then
log_error "Usage: b conf <config_name> [files...]"
exit 1
fi
shift
config_dir=""
if [ -d "$HOME/.config/$config_name" ]; then
config_dir="$HOME/.config/$config_name"
else
# Find matching directory case-insensitively using pure Bash
for d in "$HOME/.config"/*; do
if [ -d "$d" ]; then
basename="${d##*/}"
if [[ "${basename,,}" == *"${config_name,,}"* ]]; then
config_dir="$d"
break
fi
fi
done
fi
if [ -n "$config_dir" ] && [ -d "$config_dir" ]; then
editor="${EDITOR:-nvim}"
log_info "Opening editor in $config_dir"
# Run editor in a subshell so parent working directory is unchanged
(
cd "$config_dir" || exit 1
if [ $# -gt 0 ]; then
"$editor" "$@"
else
"$editor" .
fi
)
else
log_error "Could not find config directory matching: $config_name"
exit 1
fi

13
commands/help.sh Normal file
View File

@@ -0,0 +1,13 @@
# Command: help
# Lists all available bootstrap commands and installers
echo "Available bootstrap commands:"
# Non-installers first (aligned to 6 chars width)
printf " %-6s - %s\n" "all" "List all available commands"
printf " %-6s - %s\n" "conf" "Edit config (e.g. b conf nvim)"
printf " %-6s - %s\n" "bye" "Uninstall Bootstrap CLI helper"
# Installers second
for key in "${INSTALLER_KEYS[@]}"; do
printf " %-6s - %s\n" "$key" "${INSTALLERS[$key]}"
done

26
commands/uninstall.sh Normal file
View File

@@ -0,0 +1,26 @@
# Command: uninstall (bye)
# Removes bootstrap CLI and cleans up shell configuration files
# Source libraries if needed (should already be sourced by routes.sh, but just in case)
if [ -z "${_LIB_SHELL_CONFIG_SOURCED:-}" ]; then
_LIB_DIR="${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}/lib"
. "$_LIB_DIR/shell_config.sh"
fi
log_info "Removing bootstrap CLI completely..."
# Get targets using the library function
IFS=' ' read -ra target_files <<< "$(get_shell_configs)"
for config_file in "${target_files[@]}"; do
# Remove loader setup block
remove_block "$config_file" "bootstrap-cli setup"
# Remove old embedded b function block
remove_block "$config_file" "bootstrap-cli b function"
done
# Remove the installation directory
rm -rf "${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}"
log_success "Bootstrap CLI removed successfully. (Note: Run 'unset -f b' to clear it from the current session)"