diff --git a/color-tool b/color-tool index 646dbff..1960a95 100755 --- a/color-tool +++ b/color-tool @@ -341,6 +341,19 @@ reset_config() { # ── 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() { printf "\n" # 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}--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}--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}--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} \"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}[desktop]${RESET} keys: ${CYAN}output json name notify copy swatch${RESET} ${DIM}(pick always on)${RESET}\n\n" } @@ -651,7 +664,7 @@ do_install() { local dirs=("$BIN_DIR" "$DATA_DIR" "$CONFIG_DIR" "$APP_DIR") for dir in "${dirs[@]}"; do if [[ ! -d "$dir" ]]; then - printf " ${DIM}Creating %s...${RESET}\n" "$dir" + printf " ${DIM}Creating %s...${RESET}\n" "$(tilde_path "$dir")" mkdir -p "$dir" fi done @@ -665,9 +678,9 @@ do_install() { # Config setup if [[ ! -f "$CONFIG_FILE" ]]; then 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 - printf " ${BOLD}${GREEN}config${RESET} %s\n" "$CONFIG_FILE" + printf " ${BOLD}${GREEN}config${RESET} %s\n" "$(tilde_path "$CONFIG_FILE")" fi # Desktop Entry (using consolidated BIN_PATH) @@ -686,13 +699,13 @@ NoDisplay=false EOF # Summary output - printf " ${BOLD}${GREEN}app${RESET} %s\n" "$DESKTOP_FILE" - printf " ${BOLD}${GREEN}data${RESET} %s/\n" "$DATA_DIR" - printf " ${BOLD}${GREEN}bin${RESET} %s -> %s\n" "$BIN_PATH" "$DATA_DIR/color-tool" + printf " ${BOLD}${GREEN}app${RESET} %s\n" "$(tilde_path "$DESKTOP_FILE")" + printf " ${BOLD}${GREEN}data${RESET} %s/\n" "$(tilde_path "$DATA_DIR")" + printf " ${BOLD}${GREEN}bin${RESET} %s -> %s\n" "$(tilde_path "$BIN_PATH")" "$(tilde_path "$DATA_DIR/color-tool")" # Path verification 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" fi @@ -709,67 +722,67 @@ do_uninstall() { printf " ${DIM}Removing binary symlink...${RESET}\n" if [[ -L "$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 - 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)) fi 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 - 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 # 2. Desktop entry printf " ${DIM}Removing desktop entry...${RESET}\n" if [[ -f "$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 - 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)) fi 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 # 3. Data directory printf " ${DIM}Removing data directory...${RESET}\n" if [[ -d "$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 - 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)) fi 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 # 4. Config directory — prompt if interactive, skip silently if not if [[ -d "$CONFIG_DIR" ]]; then if [[ -t 0 ]]; then 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} " local answer read -r answer if [[ "${answer,,}" == "y" || "${answer,,}" == "yes" ]]; then remove_config=1 else - printf " ${BOLD}${DIM}config${RESET} %s/ kept\n" "$CONFIG_DIR" + printf " ${BOLD}${DIM}config${RESET} %s/ kept\n" "$(tilde_path "$CONFIG_DIR")" fi 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 if [[ $remove_config -eq 1 ]]; then printf " ${DIM}Removing configuration directory...${RESET}\n" 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 - 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)) fi fi @@ -790,9 +803,9 @@ do_uninstall() { local path="${paths[$i]}" printf " " 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 - 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)) fi done