Compare commits
1 Commits
main
..
9ff6a58814
| Author | SHA1 | Date | |
|---|---|---|---|
|
9ff6a58814
|
+28
-47
@@ -341,19 +341,6 @@ 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
|
||||
@@ -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}--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" "$(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}--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} \"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}[desktop]${RESET} keys: ${CYAN}output json name notify copy swatch${RESET} ${DIM}(pick always on)${RESET}\n\n"
|
||||
}
|
||||
@@ -585,15 +572,9 @@ check_deps() {
|
||||
_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 "curl" "command -v curl >/dev/null" "Fetching color names from API" 0
|
||||
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"
|
||||
_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
|
||||
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
|
||||
_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
|
||||
@@ -670,7 +651,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" "$(tilde_path "$dir")"
|
||||
printf " ${DIM}Creating %s...${RESET}\n" "$dir"
|
||||
mkdir -p "$dir"
|
||||
fi
|
||||
done
|
||||
@@ -684,9 +665,9 @@ do_install() {
|
||||
# Config setup
|
||||
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||
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
|
||||
printf " ${BOLD}${GREEN}config${RESET} %s\n" "$(tilde_path "$CONFIG_FILE")"
|
||||
printf " ${BOLD}${GREEN}config${RESET} %s\n" "$CONFIG_FILE"
|
||||
fi
|
||||
|
||||
# Desktop Entry (using consolidated BIN_PATH)
|
||||
@@ -705,13 +686,13 @@ NoDisplay=false
|
||||
EOF
|
||||
|
||||
# Summary output
|
||||
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")"
|
||||
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"
|
||||
|
||||
# Path verification
|
||||
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"
|
||||
fi
|
||||
|
||||
@@ -728,67 +709,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" "$(tilde_path "$BIN_PATH")"
|
||||
printf " ${BOLD}${GREEN}bin${RESET} Removed %s\n" "$BIN_PATH"
|
||||
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))
|
||||
fi
|
||||
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
|
||||
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
|
||||
|
||||
# 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" "$(tilde_path "$DESKTOP_FILE")"
|
||||
printf " ${BOLD}${GREEN}app${RESET} Removed %s\n" "$DESKTOP_FILE"
|
||||
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))
|
||||
fi
|
||||
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
|
||||
|
||||
# 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" "$(tilde_path "$DATA_DIR")"
|
||||
printf " ${BOLD}${GREEN}data${RESET} Removed %s/\n" "$DATA_DIR"
|
||||
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))
|
||||
fi
|
||||
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
|
||||
|
||||
# 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" "$(tilde_path "$CONFIG_DIR")"
|
||||
printf " ${DIM}%s/${RESET}\n" "$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" "$(tilde_path "$CONFIG_DIR")"
|
||||
printf " ${BOLD}${DIM}config${RESET} %s/ kept\n" "$CONFIG_DIR"
|
||||
fi
|
||||
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
|
||||
|
||||
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" "$(tilde_path "$CONFIG_DIR")"
|
||||
printf " ${BOLD}${GREEN}config${RESET} Removed %s/\n" "$CONFIG_DIR"
|
||||
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))
|
||||
fi
|
||||
fi
|
||||
@@ -809,9 +790,9 @@ do_uninstall() {
|
||||
local path="${paths[$i]}"
|
||||
printf " "
|
||||
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
|
||||
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))
|
||||
fi
|
||||
done
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ fi
|
||||
|
||||
# 16. Uninstall — removes installed files, config is kept in non-interactive mode
|
||||
it "uninstalls installed files (keeps config)"
|
||||
uninstall_out=$("$COLOR_TOOL" --uninstall </dev/null 2>&1)
|
||||
uninstall_out=$("$COLOR_TOOL" --uninstall 2>&1)
|
||||
if [[ ! -e "$HOME/.local/bin/color-tool" ]] &&
|
||||
[[ ! -L "$HOME/.local/bin/color-tool" ]] &&
|
||||
[[ ! -d "$XDG_DATA_HOME/color-tool" ]] &&
|
||||
|
||||
Reference in New Issue
Block a user