diff --git a/modules/apps/kate/check-theme-name-free.sh b/modules/apps/kate/check-theme-name-free.sh index d5cca0ff..996f2ea6 100755 --- a/modules/apps/kate/check-theme-name-free.sh +++ b/modules/apps/kate/check-theme-name-free.sh @@ -13,14 +13,13 @@ NORMAL=$(tput sgr0) # # # # https://www.baeldung.com/linux/bash-check-script-arguments -if [[ "$#" -ne 2 ]]; then +if [[ "$#" -ne 1 ]]; then # https://stackoverflow.com/questions/3005963/how-can-i-have-a-newline-in-a-string-in-sh/3182519#3182519 - >&2 printf "${RED}${BOLD}Incorrect number of arguments.${NORMAL}${RED} Expected three:\n * Name of the theme that should not already be in use\n * the path to the jq executable" + >&2 printf "%sIncorrect number of arguments.%s Expected one: The name of the theme that should not already be in use" "${RED}${BOLD}" "${NORMAL}${RED}" exit 1 fi THEMENAME=$1 -jqexec=$2 # ===================================== @@ -30,17 +29,16 @@ jqexec=$2 THEME_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/org.kde.syntax-highlighting/themes/" -ls "${THEME_DIR}" | while read -r themefile; do - FULL_PATH="${THEME_DIR}/${themefile}" - THIS_THEMENAME=$(${jqexec} -r .metadata.name "${FULL_PATH}") - # TODO skip if file is a symlink to /nix/store" +# TODO and symlinks! (or: skip over dirs) +find "${THEME_DIR}" \( -type f -o -type l \) | while read -r themefile; do + THIS_THEMENAME=$(jq -r .metadata.name "${themefile}") - if [[ "${THIS_THEMENAME}" == "${THEMENAME}" ]]; then + if [[ "${THIS_THEMENAME}" == "${themefile}" ]]; then # make sure to not look at symbolic links to the nix store # https://stackoverflow.com/questions/17918367/linux-shell-verify-whether-a-file-exists-and-is-a-soft-link/17918442#17918442 # https://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value/2172367#2172367 - if [[ ! ( -L "${FULL_PATH}" && $(readlink -f "${FULL_PATH}") == /nix/store/* ) ]]; then - >&2 printf "${RED}${BOLD}In ${THEME_DIR} there is already a theme with the name ${THEMENAME} (${themefile}).${NORMAL}${RED} You could rename the theme given in config.programs.kate.editor.theme.src by changing the value for metadta.name inside the theme." + if [[ ! ( -L "${themefile}" && $(readlink -f "${themefile}") == /nix/store/* ) ]]; then + >&2 printf "%s In %s there is already a theme with the name %s (%s).%s You could rename the theme given in config.programs.kate.editor.theme.src by changing the value for metadata.name inside the theme." "${RED}${BOLD}" "${THEME_DIR}" "${THEMENAME}" "${themefile}" "${NORMAL}${RED}" exit 1 # even on dryrun fi fi diff --git a/modules/apps/kate/default.nix b/modules/apps/kate/default.nix index 8a42b5d5..1d24683e 100644 --- a/modules/apps/kate/default.nix +++ b/modules/apps/kate/default.nix @@ -13,6 +13,19 @@ let if (indentSettings.undoByShiftTab && indentSettings.tabFromEverywhere) then 1 else 2 ); + + checkThemeNameScript = pkgs.writeShellApplication { + name = "checkThemeName"; + runtimeInputs = with pkgs; [ jq ]; + text = builtins.readFile ./check-theme-name-free.sh; + }; + + checkThemeName = name: + '' + ${checkThemeNameScript}/bin/checkThemeName ${name} + ''; + + script = pkgs.writeScript "kate-check" (checkThemeName cfg.editor.theme.name); in { options.programs.kate = { @@ -167,9 +180,13 @@ in # In case of using a custom theme, check that there is no name collision home.activation.checkKateTheme = lib.mkIf (cfg.enable && cfg.editor.theme.src != null) (lib.hm.dag.entryBefore [ "writeBoundary" ] '' - ${./check-theme-name-free.sh} ${cfg.editor.theme.name} ${pkgs.jq}/bin/jq + $DRY_RUN_CMD ${script} ''); +# ${./check-theme-name-free.sh} ${cfg.editor.theme.name} ${pkgs.jq}/bin/jq # In case of using a system theme, there should be a check that there exists such a theme + # but I could not figure out where to find them + # That's why there is no check for now + # See also [the original PR](https://github.com/pjones/plasma-manager/pull/95#issue-2206192839) }; }