1 Commits

Author SHA1 Message Date
rootiest 9ff6a58814 feat: XDG Base Directory compliance, --uninstall flag, and xclip advisory
Test PR / test (pull_request) Successful in 7s
Auto Label PRs / label (pull_request) Successful in 3s
- Resolve all paths via $XDG_CONFIG_HOME, $XDG_DATA_HOME, and
  $XDG_RUNTIME_DIR with conventional fallbacks (~/.config,
  ~/.local/share, /tmp); BIN_DIR stays ~/.local/bin (no XDG standard)
- Add --uninstall: removes symlink, desktop entry, and data dir with
  colored per-step output; prompts to remove config when interactive,
  skips silently when not; post-run verification reports any failures
- Warn in --check-deps and --install when only xclip is present —
  xclip operates through XWayland and can be unreliable on Wayland
- Normalize dependency messages to package names (wl-clipboard, xclip)
- Update README: XDG paths in install steps, --uninstall in usage,
  xclip advisory in prerequisites
- Fix test sandbox: export XDG_CONFIG_HOME and XDG_DATA_HOME so the
  overridden HOME is respected; add install (test 15) and uninstall
  (test 16) coverage; add cp and ln to mocked tool set

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-08 23:15:34 -04:00
+26 -39
View File
@@ -341,19 +341,6 @@ reset_config() {
# ── Help ────────────────────────────────────────────────────────────────────── # ── Help ──────────────────────────────────────────────────────────────────────
# Replace the $HOME prefix with ~/ only when the path actually starts with
# $HOME — avoids false matches on other users' home dirs or custom XDG roots.
tilde_path() {
local path="$1"
if [[ "$path" == "$HOME/"* ]]; then
printf '%s' "~/${path#"$HOME/"}"
elif [[ "$path" == "$HOME" ]]; then
printf '%s' "~"
else
printf '%s' "$path"
fi
}
show_help() { show_help() {
printf "\n" printf "\n"
# Title: "color" in a rainbow gradient, "-tool" in bold # Title: "color" in a rainbow gradient, "-tool" in bold
@@ -375,7 +362,7 @@ show_help() {
printf " ${BOLD}${CYAN}--set-config${RESET} Update the configuration ${DIM}(e.g. --set-config desktop --copy)${RESET}\n" printf " ${BOLD}${CYAN}--set-config${RESET} Update the configuration ${DIM}(e.g. --set-config desktop --copy)${RESET}\n"
printf " ${BOLD}${CYAN}--reset-config${RESET} Restore the configuration file to its default values\n" printf " ${BOLD}${CYAN}--reset-config${RESET} Restore the configuration file to its default values\n"
printf " ${BOLD}${CYAN}--check-deps${RESET} Check system dependencies and environment support\n" printf " ${BOLD}${CYAN}--check-deps${RESET} Check system dependencies and environment support\n"
printf " ${BOLD}${CYAN}--install${RESET} Install to %s/ and symlink into %s/\n" "$(tilde_path "$DATA_DIR")" "$(tilde_path "$BIN_DIR")" printf " ${BOLD}${CYAN}--install${RESET} Install to %s/ and symlink into %s/\n" "$DATA_DIR" "$BIN_DIR"
printf " ${BOLD}${CYAN}--uninstall${RESET} Remove installed files and optionally the configuration\n" printf " ${BOLD}${CYAN}--uninstall${RESET} Remove installed files and optionally the configuration\n"
printf " ${BOLD}${CYAN}--help${RESET}, ${BOLD}${CYAN}-h${RESET} Show this help message\n\n" printf " ${BOLD}${CYAN}--help${RESET}, ${BOLD}${CYAN}-h${RESET} Show this help message\n\n"
@@ -384,7 +371,7 @@ show_help() {
printf " ${CYAN}${0##*/}${RESET} --pick --output rgb,hsl --json\n" printf " ${CYAN}${0##*/}${RESET} --pick --output rgb,hsl --json\n"
printf " ${CYAN}${0##*/}${RESET} \"rgb(255, 100, 0)\" --output hex,hsla\n\n" printf " ${CYAN}${0##*/}${RESET} \"rgb(255, 100, 0)\" --output hex,hsla\n\n"
printf " ${BOLD}${YELLOW}Config${RESET} ${DIM}%s${RESET}\n" "$(tilde_path "$CONFIG_FILE")" printf " ${BOLD}${YELLOW}Config${RESET} ${DIM}%s${RESET}\n" "$CONFIG_FILE"
printf " ${DIM}[defaults]${RESET} keys: ${CYAN}output json swatch name copy pick notify${RESET}\n" printf " ${DIM}[defaults]${RESET} keys: ${CYAN}output json swatch name copy pick notify${RESET}\n"
printf " ${DIM}[desktop]${RESET} keys: ${CYAN}output json name notify copy swatch${RESET} ${DIM}(pick always on)${RESET}\n\n" printf " ${DIM}[desktop]${RESET} keys: ${CYAN}output json name notify copy swatch${RESET} ${DIM}(pick always on)${RESET}\n\n"
} }
@@ -664,7 +651,7 @@ do_install() {
local dirs=("$BIN_DIR" "$DATA_DIR" "$CONFIG_DIR" "$APP_DIR") local dirs=("$BIN_DIR" "$DATA_DIR" "$CONFIG_DIR" "$APP_DIR")
for dir in "${dirs[@]}"; do for dir in "${dirs[@]}"; do
if [[ ! -d "$dir" ]]; then if [[ ! -d "$dir" ]]; then
printf " ${DIM}Creating %s...${RESET}\n" "$(tilde_path "$dir")" printf " ${DIM}Creating %s...${RESET}\n" "$dir"
mkdir -p "$dir" mkdir -p "$dir"
fi fi
done done
@@ -678,9 +665,9 @@ do_install() {
# Config setup # Config setup
if [[ ! -f "$CONFIG_FILE" ]]; then if [[ ! -f "$CONFIG_FILE" ]]; then
write_default_config write_default_config
printf " ${BOLD}${GREEN}config${RESET} %s ${DIM}(sample created)${RESET}\n" "$(tilde_path "$CONFIG_FILE")" printf " ${BOLD}${GREEN}config${RESET} %s ${DIM}(sample created)${RESET}\n" "$CONFIG_FILE"
else else
printf " ${BOLD}${GREEN}config${RESET} %s\n" "$(tilde_path "$CONFIG_FILE")" printf " ${BOLD}${GREEN}config${RESET} %s\n" "$CONFIG_FILE"
fi fi
# Desktop Entry (using consolidated BIN_PATH) # Desktop Entry (using consolidated BIN_PATH)
@@ -699,13 +686,13 @@ NoDisplay=false
EOF EOF
# Summary output # Summary output
printf " ${BOLD}${GREEN}app${RESET} %s\n" "$(tilde_path "$DESKTOP_FILE")" printf " ${BOLD}${GREEN}app${RESET} %s\n" "$DESKTOP_FILE"
printf " ${BOLD}${GREEN}data${RESET} %s/\n" "$(tilde_path "$DATA_DIR")" printf " ${BOLD}${GREEN}data${RESET} %s/\n" "$DATA_DIR"
printf " ${BOLD}${GREEN}bin${RESET} %s -> %s\n" "$(tilde_path "$BIN_PATH")" "$(tilde_path "$DATA_DIR/color-tool")" printf " ${BOLD}${GREEN}bin${RESET} %s -> %s\n" "$BIN_PATH" "$DATA_DIR/color-tool"
# Path verification # Path verification
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
printf "\n${BOLD}${YELLOW}Warning:${RESET} %s is not in your PATH.\n" "$(tilde_path "$BIN_DIR")" printf "\n${BOLD}${YELLOW}Warning:${RESET} %s is not in your PATH.\n" "$BIN_DIR"
suggest_path_add "$BIN_DIR" suggest_path_add "$BIN_DIR"
fi fi
@@ -722,67 +709,67 @@ do_uninstall() {
printf " ${DIM}Removing binary symlink...${RESET}\n" printf " ${DIM}Removing binary symlink...${RESET}\n"
if [[ -L "$BIN_PATH" ]]; then if [[ -L "$BIN_PATH" ]]; then
if rm "$BIN_PATH"; then if rm "$BIN_PATH"; then
printf " ${BOLD}${GREEN}bin${RESET} Removed %s\n" "$(tilde_path "$BIN_PATH")" printf " ${BOLD}${GREEN}bin${RESET} Removed %s\n" "$BIN_PATH"
else else
printf " ${BOLD}${RED}bin${RESET} Failed to remove %s\n" "$(tilde_path "$BIN_PATH")" >&2 printf " ${BOLD}${RED}bin${RESET} Failed to remove %s\n" "$BIN_PATH" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
elif [[ -e "$BIN_PATH" ]]; then elif [[ -e "$BIN_PATH" ]]; then
printf " ${BOLD}${YELLOW}bin${RESET} %s is not a symlink — skipping\n" "$(tilde_path "$BIN_PATH")" printf " ${BOLD}${YELLOW}bin${RESET} %s is not a symlink — skipping\n" "$BIN_PATH"
else else
printf " ${DIM}bin${RESET} %s not found — skipping\n" "$(tilde_path "$BIN_PATH")" printf " ${DIM}bin${RESET} %s not found — skipping\n" "$BIN_PATH"
fi fi
# 2. Desktop entry # 2. Desktop entry
printf " ${DIM}Removing desktop entry...${RESET}\n" printf " ${DIM}Removing desktop entry...${RESET}\n"
if [[ -f "$DESKTOP_FILE" ]]; then if [[ -f "$DESKTOP_FILE" ]]; then
if rm "$DESKTOP_FILE"; then if rm "$DESKTOP_FILE"; then
printf " ${BOLD}${GREEN}app${RESET} Removed %s\n" "$(tilde_path "$DESKTOP_FILE")" printf " ${BOLD}${GREEN}app${RESET} Removed %s\n" "$DESKTOP_FILE"
else else
printf " ${BOLD}${RED}app${RESET} Failed to remove %s\n" "$(tilde_path "$DESKTOP_FILE")" >&2 printf " ${BOLD}${RED}app${RESET} Failed to remove %s\n" "$DESKTOP_FILE" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
else else
printf " ${DIM}app${RESET} %s not found — skipping\n" "$(tilde_path "$DESKTOP_FILE")" printf " ${DIM}app${RESET} %s not found — skipping\n" "$DESKTOP_FILE"
fi fi
# 3. Data directory # 3. Data directory
printf " ${DIM}Removing data directory...${RESET}\n" printf " ${DIM}Removing data directory...${RESET}\n"
if [[ -d "$DATA_DIR" ]]; then if [[ -d "$DATA_DIR" ]]; then
if rm -rf "$DATA_DIR"; then if rm -rf "$DATA_DIR"; then
printf " ${BOLD}${GREEN}data${RESET} Removed %s/\n" "$(tilde_path "$DATA_DIR")" printf " ${BOLD}${GREEN}data${RESET} Removed %s/\n" "$DATA_DIR"
else else
printf " ${BOLD}${RED}data${RESET} Failed to remove %s/\n" "$(tilde_path "$DATA_DIR")" >&2 printf " ${BOLD}${RED}data${RESET} Failed to remove %s/\n" "$DATA_DIR" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
else else
printf " ${DIM}data${RESET} %s not found — skipping\n" "$(tilde_path "$DATA_DIR")" printf " ${DIM}data${RESET} %s not found — skipping\n" "$DATA_DIR"
fi fi
# 4. Config directory — prompt if interactive, skip silently if not # 4. Config directory — prompt if interactive, skip silently if not
if [[ -d "$CONFIG_DIR" ]]; then if [[ -d "$CONFIG_DIR" ]]; then
if [[ -t 0 ]]; then if [[ -t 0 ]]; then
printf "\n ${BOLD}${YELLOW}?${RESET} Remove configuration directory?\n" printf "\n ${BOLD}${YELLOW}?${RESET} Remove configuration directory?\n"
printf " ${DIM}%s/${RESET}\n" "$(tilde_path "$CONFIG_DIR")" printf " ${DIM}%s/${RESET}\n" "$CONFIG_DIR"
printf " ${BOLD}[y/N]${RESET} " printf " ${BOLD}[y/N]${RESET} "
local answer local answer
read -r answer read -r answer
if [[ "${answer,,}" == "y" || "${answer,,}" == "yes" ]]; then if [[ "${answer,,}" == "y" || "${answer,,}" == "yes" ]]; then
remove_config=1 remove_config=1
else else
printf " ${BOLD}${DIM}config${RESET} %s/ kept\n" "$(tilde_path "$CONFIG_DIR")" printf " ${BOLD}${DIM}config${RESET} %s/ kept\n" "$CONFIG_DIR"
fi fi
else else
printf " ${DIM}config${RESET} Non-interactive mode — keeping %s/\n" "$(tilde_path "$CONFIG_DIR")" printf " ${DIM}config${RESET} Non-interactive mode — keeping %s/\n" "$CONFIG_DIR"
fi fi
fi fi
if [[ $remove_config -eq 1 ]]; then if [[ $remove_config -eq 1 ]]; then
printf " ${DIM}Removing configuration directory...${RESET}\n" printf " ${DIM}Removing configuration directory...${RESET}\n"
if rm -rf "$CONFIG_DIR"; then if rm -rf "$CONFIG_DIR"; then
printf " ${BOLD}${GREEN}config${RESET} Removed %s/\n" "$(tilde_path "$CONFIG_DIR")" printf " ${BOLD}${GREEN}config${RESET} Removed %s/\n" "$CONFIG_DIR"
else else
printf " ${BOLD}${RED}config${RESET} Failed to remove %s/\n" "$(tilde_path "$CONFIG_DIR")" >&2 printf " ${BOLD}${RED}config${RESET} Failed to remove %s/\n" "$CONFIG_DIR" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
fi fi
@@ -803,9 +790,9 @@ do_uninstall() {
local path="${paths[$i]}" local path="${paths[$i]}"
printf " " printf " "
if [[ ! -e "$path" && ! -L "$path" ]]; then if [[ ! -e "$path" && ! -L "$path" ]]; then
printf "${GREEN}✔${RESET} %-8s %s\n" "$label" "$(tilde_path "$path")" printf "${GREEN}✔${RESET} %-8s %s\n" "$label" "$path"
else else
printf "${RED}✘${RESET} %-8s %s ${RED}(still present)${RESET}\n" "$label" "$(tilde_path "$path")" printf "${RED}✘${RESET} %-8s %s ${RED}(still present)${RESET}\n" "$label" "$path"
verify_errors=$((verify_errors + 1)) verify_errors=$((verify_errors + 1))
fi fi
done done