5 Commits

Author SHA1 Message Date
rootiest c206d78ce7 Merge pull request 'feat: XDG Base Directory compliance, --uninstall flag, and xclip advisory' (#13) from feat/xdg-compliance-and-uninstall into main
Reviewed-on: #13
2026-05-09 05:02:15 +00:00
rootiest 1a27dbde4e fix(tests): redirect stdin from /dev/null in uninstall test to prevent hang
Test PR / test (pull_request) Successful in 6s
Auto Label PRs / label (pull_request) Successful in 3s
Release on Merge / release (pull_request) Successful in 7s
--uninstall prompts for config removal when stdin is a TTY. Running the
test from an interactive terminal caused it to block on read. Feeding
/dev/null forces the non-interactive path without changing behaviour.
2026-05-09 01:00:31 -04:00
rootiest ad7a1f15b3 fix(deps): dynamic clipboard label and yellow check for xclip-only in --check-deps
Test PR / test (pull_request) Successful in 6s
Auto Label PRs / label (pull_request) Successful in 2s
Show only the binary(s) actually present in the clipboard row label,
and use a yellow ✔ (instead of green) when only xclip is found so the
degraded state stands out from a fully-satisfied check.
2026-05-09 00:57:42 -04:00
rootiest 06dd84d3a3 refactor: apply tilde_path to all user-facing path output
Test PR / test (pull_request) Successful in 7s
Auto Label PRs / label (pull_request) Successful in 3s
All paths printed to the user in --help, --install, and --uninstall
now display as ~/... when the path falls under $HOME, and as a full
absolute path otherwise. Actual file operations continue to use the
original absolute paths unchanged.
2026-05-08 23:43:58 -04:00
rootiest 075bb10265 feat: XDG Base Directory compliance, --uninstall flag, and xclip advisory
- 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
2026-05-08 23:43:58 -04:00
2 changed files with 48 additions and 29 deletions
+47 -28
View File
@@ -341,6 +341,19 @@ 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
@@ -362,7 +375,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" "$DATA_DIR" "$BIN_DIR" printf " ${BOLD}${CYAN}--install${RESET} Install to %s/ and symlink into %s/\n" "$(tilde_path "$DATA_DIR")" "$(tilde_path "$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"
@@ -371,7 +384,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" "$CONFIG_FILE" printf " ${BOLD}${YELLOW}Config${RESET} ${DIM}%s${RESET}\n" "$(tilde_path "$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"
} }
@@ -572,9 +585,15 @@ check_deps() {
_check "python3-pyqt6" "python3 -c 'import PyQt6.QtDBus' 2>/dev/null" "KDE color picker interface" 0 _check "python3-pyqt6" "python3 -c 'import PyQt6.QtDBus' 2>/dev/null" "KDE color picker interface" 0
_check "jq" "command -v jq >/dev/null" "JSON output and data parsing" 1 _check "jq" "command -v jq >/dev/null" "JSON output and data parsing" 1
_check "curl" "command -v curl >/dev/null" "Fetching color names from API" 0 _check "curl" "command -v curl >/dev/null" "Fetching color names from API" 0
_check "wl-clipboard / xclip" "command -v wl-copy >/dev/null || command -v xclip >/dev/null" "System clipboard integration" 0 if command -v wl-copy >/dev/null 2>&1 && command -v xclip >/dev/null 2>&1; then
if ! command -v wl-copy >/dev/null 2>&1 && command -v xclip >/dev/null 2>&1; then printf " ${GREEN}✔${RESET} %-25s ${DIM}%s${RESET}\n" "wl-clipboard / xclip" "System clipboard integration"
elif command -v wl-copy >/dev/null 2>&1; then
printf " ${GREEN}✔${RESET} %-25s ${DIM}%s${RESET}\n" "wl-clipboard" "System clipboard integration"
elif command -v xclip >/dev/null 2>&1; then
printf " ${YELLOW}✔${RESET} %-25s ${DIM}%s${RESET}\n" "xclip" "System clipboard integration"
printf " ${YELLOW} └─ xclip found but wl-clipboard is missing — xclip operates through XWayland and may be unreliable on Wayland${RESET}\n" printf " ${YELLOW} └─ xclip found but wl-clipboard is missing — xclip operates through XWayland and may be unreliable on Wayland${RESET}\n"
else
printf " ${YELLOW}⚠${RESET} %-25s ${DIM}%s${RESET}\n" "wl-clipboard / xclip" "System clipboard integration"
fi fi
_check "libnotify" "command -v notify-send >/dev/null" "Desktop notifications" 0 _check "libnotify" "command -v notify-send >/dev/null" "Desktop notifications" 0
_check "ImageMagick" "command -v magick >/dev/null || command -v convert >/dev/null" "Color swatches in notifications" 0 _check "ImageMagick" "command -v magick >/dev/null || command -v convert >/dev/null" "Color swatches in notifications" 0
@@ -651,7 +670,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" "$dir" printf " ${DIM}Creating %s...${RESET}\n" "$(tilde_path "$dir")"
mkdir -p "$dir" mkdir -p "$dir"
fi fi
done done
@@ -665,9 +684,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" "$CONFIG_FILE" printf " ${BOLD}${GREEN}config${RESET} %s ${DIM}(sample created)${RESET}\n" "$(tilde_path "$CONFIG_FILE")"
else else
printf " ${BOLD}${GREEN}config${RESET} %s\n" "$CONFIG_FILE" printf " ${BOLD}${GREEN}config${RESET} %s\n" "$(tilde_path "$CONFIG_FILE")"
fi fi
# Desktop Entry (using consolidated BIN_PATH) # Desktop Entry (using consolidated BIN_PATH)
@@ -686,13 +705,13 @@ NoDisplay=false
EOF EOF
# Summary output # Summary output
printf " ${BOLD}${GREEN}app${RESET} %s\n" "$DESKTOP_FILE" printf " ${BOLD}${GREEN}app${RESET} %s\n" "$(tilde_path "$DESKTOP_FILE")"
printf " ${BOLD}${GREEN}data${RESET} %s/\n" "$DATA_DIR" printf " ${BOLD}${GREEN}data${RESET} %s/\n" "$(tilde_path "$DATA_DIR")"
printf " ${BOLD}${GREEN}bin${RESET} %s -> %s\n" "$BIN_PATH" "$DATA_DIR/color-tool" printf " ${BOLD}${GREEN}bin${RESET} %s -> %s\n" "$(tilde_path "$BIN_PATH")" "$(tilde_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" "$BIN_DIR" printf "\n${BOLD}${YELLOW}Warning:${RESET} %s is not in your PATH.\n" "$(tilde_path "$BIN_DIR")"
suggest_path_add "$BIN_DIR" suggest_path_add "$BIN_DIR"
fi fi
@@ -709,67 +728,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" "$BIN_PATH" printf " ${BOLD}${GREEN}bin${RESET} Removed %s\n" "$(tilde_path "$BIN_PATH")"
else else
printf " ${BOLD}${RED}bin${RESET} Failed to remove %s\n" "$BIN_PATH" >&2 printf " ${BOLD}${RED}bin${RESET} Failed to remove %s\n" "$(tilde_path "$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" "$BIN_PATH" printf " ${BOLD}${YELLOW}bin${RESET} %s is not a symlink — skipping\n" "$(tilde_path "$BIN_PATH")"
else else
printf " ${DIM}bin${RESET} %s not found — skipping\n" "$BIN_PATH" printf " ${DIM}bin${RESET} %s not found — skipping\n" "$(tilde_path "$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" "$DESKTOP_FILE" printf " ${BOLD}${GREEN}app${RESET} Removed %s\n" "$(tilde_path "$DESKTOP_FILE")"
else else
printf " ${BOLD}${RED}app${RESET} Failed to remove %s\n" "$DESKTOP_FILE" >&2 printf " ${BOLD}${RED}app${RESET} Failed to remove %s\n" "$(tilde_path "$DESKTOP_FILE")" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
else else
printf " ${DIM}app${RESET} %s not found — skipping\n" "$DESKTOP_FILE" printf " ${DIM}app${RESET} %s not found — skipping\n" "$(tilde_path "$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" "$DATA_DIR" printf " ${BOLD}${GREEN}data${RESET} Removed %s/\n" "$(tilde_path "$DATA_DIR")"
else else
printf " ${BOLD}${RED}data${RESET} Failed to remove %s/\n" "$DATA_DIR" >&2 printf " ${BOLD}${RED}data${RESET} Failed to remove %s/\n" "$(tilde_path "$DATA_DIR")" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
else else
printf " ${DIM}data${RESET} %s not found — skipping\n" "$DATA_DIR" printf " ${DIM}data${RESET} %s not found — skipping\n" "$(tilde_path "$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" "$CONFIG_DIR" printf " ${DIM}%s/${RESET}\n" "$(tilde_path "$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" "$CONFIG_DIR" printf " ${BOLD}${DIM}config${RESET} %s/ kept\n" "$(tilde_path "$CONFIG_DIR")"
fi fi
else else
printf " ${DIM}config${RESET} Non-interactive mode — keeping %s/\n" "$CONFIG_DIR" printf " ${DIM}config${RESET} Non-interactive mode — keeping %s/\n" "$(tilde_path "$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" "$CONFIG_DIR" printf " ${BOLD}${GREEN}config${RESET} Removed %s/\n" "$(tilde_path "$CONFIG_DIR")"
else else
printf " ${BOLD}${RED}config${RESET} Failed to remove %s/\n" "$CONFIG_DIR" >&2 printf " ${BOLD}${RED}config${RESET} Failed to remove %s/\n" "$(tilde_path "$CONFIG_DIR")" >&2
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
fi fi
@@ -790,9 +809,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" "$path" printf "${GREEN}✔${RESET} %-8s %s\n" "$label" "$(tilde_path "$path")"
else else
printf "${RED}✘${RESET} %-8s %s ${RED}(still present)${RESET}\n" "$label" "$path" printf "${RED}✘${RESET} %-8s %s ${RED}(still present)${RESET}\n" "$label" "$(tilde_path "$path")"
verify_errors=$((verify_errors + 1)) verify_errors=$((verify_errors + 1))
fi fi
done done
+1 -1
View File
@@ -259,7 +259,7 @@ fi
# 16. Uninstall — removes installed files, config is kept in non-interactive mode # 16. Uninstall — removes installed files, config is kept in non-interactive mode
it "uninstalls installed files (keeps config)" it "uninstalls installed files (keeps config)"
uninstall_out=$("$COLOR_TOOL" --uninstall 2>&1) uninstall_out=$("$COLOR_TOOL" --uninstall </dev/null 2>&1)
if [[ ! -e "$HOME/.local/bin/color-tool" ]] && if [[ ! -e "$HOME/.local/bin/color-tool" ]] &&
[[ ! -L "$HOME/.local/bin/color-tool" ]] && [[ ! -L "$HOME/.local/bin/color-tool" ]] &&
[[ ! -d "$XDG_DATA_HOME/color-tool" ]] && [[ ! -d "$XDG_DATA_HOME/color-tool" ]] &&