From 31064987613e7a604d78ce15ade7feca6a59ff18 Mon Sep 17 00:00:00 2001 From: yqrashawn Date: Sun, 17 Jul 2022 15:11:56 +0800 Subject: [PATCH] fix: resolve #181 --- CHANGELOG.org | 10 +++++- src/karabiner_configurator/core.clj | 46 +++++++++++++----------- src/karabiner_configurator/modifiers.clj | 13 +++---- src/karabiner_configurator/profiles.clj | 1 + 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index f263108..cf13e04 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -3,7 +3,15 @@ All notable changes to this project will be documented in this file. This change ** Unreleased -[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.5.5...HEAD +[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.5.6...HEAD + +** 0.5.6 - 2022-07-17 +*** Added +~goku --where-is-my-config- shows detected config path +*** Fixed +- fix https://github.com/yqrashawn/GokuRakuJoudo/issues/181 + +[commits in 0.5.6]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.5.5...v0.5.6 ** 0.5.5 - 2022-07-12 *** Fixed diff --git a/src/karabiner_configurator/core.clj b/src/karabiner_configurator/core.clj index 1117a97..9807194 100644 --- a/src/karabiner_configurator/core.clj +++ b/src/karabiner_configurator/core.clj @@ -37,9 +37,11 @@ "/usr/local/bin:" ;; homebrew (get sys-env "PATH"))})))) -(defn exit [status & [msg]] - (when msg (println msg)) - (when-not (env :is-dev) (System/exit status))) +(defn exit + ([status] (exit [status nil])) + ([status msg] + (when msg (println msg)) + (when-not (env :is-dev) (System/exit status)))) ;; paths (defn json-config-file-path @@ -71,7 +73,7 @@ (let [{:keys [applications devices keyboard-type input-sources tos froms modifiers layers simlayers ;; raws main simlayer-threshold templates profiles]} conf] (if (nil? profiles) - (profiles/parse-profiles (:profiles d/conf-data)) + (profiles/parse-profiles (:profiles @d/conf-data)) (profiles/parse-profiles profiles)) (update-static-conf :applications applications) (update-static-conf :devices devices) @@ -177,13 +179,13 @@ [["-h" "--help"] ["-V" "--version"] ["-l" "--log"] + [nil "--where-is-my-config"] ["-c" "--config PATH" "Config PATH" :parse-fn abs-path :validate [(fn [path] - (let [path (abs-path path)] - (and (fs/exists? path) - (fs/file? path) - (fs/readable? path)))) + (and (fs/exists? path) + (fs/file? path) + (fs/readable? path))) "Make sure the file is exits and readable"]] ["-d" "--dry-run"] ["-A" "--dry-run-all"]]) @@ -201,11 +203,14 @@ {:action "exit-with-message" :ok? true :exit-message (help-message summary)} + (:where-is-my-config options) + {:action "show-config-path" + :ok? true} ;; version (:version options) - {:action "exit-with-message" - :ok? true - :exit-message "0.5.3"} + {:action "exit-with-message" + :ok? true + :exit-message "0.5.6"} ;; log (:log options) {:action "log" @@ -229,15 +234,14 @@ [& args] (let [{:keys [action ;; options exit-message ok? config dry-run dry-run-all]} (validate-args args)] - (when exit-message - (case action - "run" (do (parse (or config (edn-config-file-path)) dry-run dry-run-all) - (exit (if ok? 0 1) exit-message)) - "log" (do (open-log-file) - (exit 0)) - "exit-with-message" (exit (if ok? 0 1) exit-message) - "errors" (exit (if ok? 0 1) exit-message) - "default" (exit (if ok? 0 1) exit-message))))) + (case action + "run" (do (parse (or config (edn-config-file-path)) dry-run dry-run-all) + (exit (if ok? 0 1) exit-message)) + "show-config-path" (exit 0 (or config (edn-config-file-path))) + "log" (do (open-log-file) (exit 0)) + "exit-with-message" (exit (if ok? 0 1) exit-message) + "errors" (exit (if ok? 0 1) exit-message) + "default" (exit (if ok? 0 1) exit-message)))) (comment (-main) @@ -246,10 +250,12 @@ (-main "-l") (-main "--log") (-main "--config" "./") + (-main "--where-is-my-config") (-main "-c" "./") (-main "-dc" "./") (-main "-dc" "~/.config/karabiner.edn") (-main "-dc" "~/.config/karabiner.test.edn") + (-main "-c" "~/.nixpkgs/modules/yqrashawn/home-manager/dotfiles/karabiner.edn") (-main "-d") (-main "-V") (-main "--version")) diff --git a/src/karabiner_configurator/modifiers.clj b/src/karabiner_configurator/modifiers.clj index d7631e2..ded0e3e 100644 --- a/src/karabiner_configurator/modifiers.clj +++ b/src/karabiner_configurator/modifiers.clj @@ -67,12 +67,13 @@ (defn generate [modifiers] - (assoc @d/conf-data :modifiers - (into - {} - (for [[modifier-name modifier-info] modifiers] - {modifier-name - (parse-single-modifier-definition modifier-info modifier-name)})))) + (d/assoc-conf-data + :modifiers + (into + {} + (for [[modifier-name modifier-info] modifiers] + {modifier-name + (parse-single-modifier-definition modifier-info modifier-name)})))) (defn parse-modifiers "parse modifires to string" diff --git a/src/karabiner_configurator/profiles.clj b/src/karabiner_configurator/profiles.clj index 6b517c3..76d7262 100644 --- a/src/karabiner_configurator/profiles.clj +++ b/src/karabiner_configurator/profiles.clj @@ -21,6 +21,7 @@ :basic.to_delayed_action_delay_milliseconds delay :basic.to_if_alone_timeout_milliseconds alone :basic.to_if_held_down_threshold_milliseconds held}}})))) + (defn parse-rules "Parse generated rules into profiles" [rules]