Skip to content

Commit 446d6c7

Browse files
committed
fix: joker path in service
1 parent 39e0e9f commit 446d6c7

19 files changed

+448
-459
lines changed

.github/workflows/build-and-release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: |
4040
touch gokuw
4141
echo '#!/bin/sh' >> gokuw
42-
echo 'watchexec -r -w `[[ -z $GOKU_EDN_CONFIG_FILE ]] && echo ~/.config/karabiner.edn || echo $GOKU_EDN_CONFIG_FILE` goku' >> gokuw
42+
echo 'watchexec -r -e edn -w `[[ -z $GOKU_EDN_CONFIG_FILE ]] && echo ~/.config/karabiner.edn || echo $GOKU_EDN_CONFIG_FILE` goku' >> gokuw
4343
chmod +x gokuw
4444
- name: Pack
4545
run: zip -r goku.zip goku.zip goku gokuw # https://github.com/actions/virtual-environments/issues/2619#issuecomment-778827140

CHANGELOG.org

+25-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ All notable changes to this project will be documented in this file. This change
33

44
** Unreleased
55

6-
[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.5.3...HEAD
6+
[Unreleased Commits]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.5.4...HEAD
7+
** 0.5.4 - 2022-07-12
8+
*** Changed
9+
- use ~/bin/zsh~ instead of ~/bin/sh~ in launch agent https://github.com/yqrashawn/homebrew-goku/blob/9a4f6cd23f51535e046a33fe260876630fc20292/Formula/goku.rb#L28
10+
- fix joker PATH
11+
- run through clj-kondo
12+
13+
[commits in 0.5.4]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.5.3...v0.5.4
714

815
** 0.5.3 - 2022-05-16
916

@@ -61,8 +68,8 @@ All notable changes to this project will be documented in this file. This change
6168
- support simultaneous pointing_button
6269
#+NAME: sim key in from
6370
#+BEGIN_SRC clojure
64-
{:des "sim pkey in from"
65-
:rules [[[{:pkey :button5} {:pkey :button2}] {:pkey :button1}]]}
71+
{:des "sim pkey in from"
72+
:rules [[[{:pkey :button5} {:pkey :button2}] {:pkey :button1}]]}
6673
#+END_SRC
6774

6875
[commits in 0.3.10]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.3.9...v0.3.10
@@ -108,18 +115,18 @@ All notable changes to this project will be documented in this file. This change
108115
- ~:applications~ now supports ~file_paths~
109116
[[https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/][karabiner-elements documentation about file_paths]]
110117
#+BEGIN_SRC clojure
111-
{...
112-
:applications
113-
{:Chromes ["^org\\.chromium\\.Chromium$" "^com\\.google\\.Chrome\\.canary$" :paths "^/Applications/Google Chrome\\.app"]
114-
;; same as
115-
:Chromes [:identifiers "^org\\.chromium\\.Chromium$" "^com\\.google\\.Chrome\\.canary$" :paths "^/Applications/Google Chrome\\.app"]
116-
117-
;; can specify multiple :paths or :identifiers (can omit keyword :identifiers)
118-
:Chromes [:identifiers "^org\\.chromium\\.Chromium$" "^com\\.google\\.Chrome\\.canary$"
119-
:paths "^/Applications/Google Chrome\\.app" "^/Applications/Google Chrome Canary\\.app"]
120-
121-
;; paths only (can't omit keyword :paths)
122-
:Chromes [:paths "^/Applications/.*Chrom.*"]}}
118+
{...
119+
:applications
120+
{:Chromes ["^org\\.chromium\\.Chromium$" "^com\\.google\\.Chrome\\.canary$" :paths "^/Applications/Google Chrome\\.app"]
121+
;; same as
122+
:Chromes [:identifiers "^org\\.chromium\\.Chromium$" "^com\\.google\\.Chrome\\.canary$" :paths "^/Applications/Google Chrome\\.app"]
123+
124+
;; can specify multiple :paths or :identifiers (can omit keyword :identifiers)
125+
:Chromes [:identifiers "^org\\.chromium\\.Chromium$" "^com\\.google\\.Chrome\\.canary$"
126+
:paths "^/Applications/Google Chrome\\.app" "^/Applications/Google Chrome Canary\\.app"]
127+
128+
;; paths only (can't omit keyword :paths)
129+
:Chromes [:paths "^/Applications/.*Chrom.*"]}}
123130
#+END_SRC
124131

125132
[commits in 0.3.4]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.3.3...0.3.4
@@ -292,9 +299,9 @@ both stderr and stdout.
292299

293300
;; now we can do it with predefined layer
294301
{:layers {:wlayer {:key :w}}
295-
:main [{:des "w layer"
296-
:rules [[:e "open -a Emacs.app" :wlayer]
297-
[:s "open -a Safari.app" :wlayer]]}]}
302+
:main [{:des "w layer"
303+
:rules [[:e "open -a Emacs.app" :wlayer]
304+
[:s "open -a Safari.app" :wlayer]]}]}
298305
#+end_src
299306

300307
- group rules by conditions
+23-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns karabiner-configurator.conditions
22
(:require
3-
[karabiner-configurator.misc :refer :all]
4-
[karabiner-configurator.data :refer :all]))
3+
[karabiner-configurator.data :refer [conf-data simlayers? input-sources? devices?]]
4+
[karabiner-configurator.misc :refer [massert]]))
55

6-
(def used-simlayers-config nil)
6+
(def used-simlayers-config (atom nil))
77

88
(defn update-used-simlayers-config [config]
9-
(def used-simlayers-config config))
9+
(reset! used-simlayers-config config))
1010

1111
(defn cleanup-used-simlayers-config []
12-
(def used-simlayers-config nil))
12+
(reset! used-simlayers-config nil))
1313

1414
(defn is-simple-set-variable? [vec]
1515
(and (= 2 (count vec)) (string? (first vec)) (number? (second vec))))
@@ -19,23 +19,23 @@
1919
[]
2020
(vec
2121
(for [condi condis
22-
:let [validate-condi
22+
:let [_validate-condi
2323
(massert (or (and (vector? condi) (is-simple-set-variable? condi)) (keyword? condi))
2424
(str "invalid condition " condi ", must be a keyword or simple condition definition"))
25-
condi!? (if (keyword? condi) (= \! (first (vec (name condi)))))
25+
condi!? (when (keyword? condi) (= \! (first (vec (name condi)))))
2626
condi (if condi!? (keyword (subs (name condi) 1))
2727
condi)
2828
result nil
2929
condi-type (if condi!?
3030
"frontmost_application_unless"
3131
"frontmost_application_if")
32-
result (if (and (keyword? condi) (nn? (condi (:applications conf-data))))
33-
(let [this-condi (condi (:applications conf-data))
34-
this-condi (if (= (first this-condi) :identifiers) this-condi (into [:identifiers] (condi (:applications conf-data))))
32+
result (if (and (keyword? condi) (some? (condi (:applications @conf-data))))
33+
(let [this-condi (condi (:applications @conf-data))
34+
this-condi (if (= (first this-condi) :identifiers) this-condi (into [:identifiers] (condi (:applications @conf-data))))
3535
[identifiers paths] [(into [] (rest (take-while (complement #{:paths}) this-condi))) (into [] (rest (drop-while (complement #{:paths}) this-condi)))]
3636
[identifiers paths] [(or identifiers []) (or paths [])]
37-
identifiers? (not (empty? identifiers))
38-
paths? (not (empty? paths))
37+
identifiers? (seq identifiers)
38+
paths? (seq paths)
3939
rst {:type condi-type}
4040
rst (if identifiers? (assoc rst :bundle_identifiers identifiers) rst)
4141
rst (if paths? (assoc rst :file_paths paths) rst)]
@@ -46,28 +46,27 @@
4646
"device_if")
4747
result (if (and (keyword? condi) (devices? condi))
4848
{:identifiers
49-
(vec (condi (:devices conf-data)))
49+
(vec (condi (:devices @conf-data)))
5050
:type condi-type}
5151
result)
5252
condi-type (if condi!?
5353
"input_source_unless"
5454
"input_source_if")
5555
result (if (and (keyword? condi) (input-sources? condi))
5656
{:input_sources
57-
[(condi (:input-sources conf-data))]
57+
[(condi (:input-sources @conf-data))]
5858
:type condi-type}
5959
result)
6060
condi-type (if condi!?
6161
"variable_unless"
6262
"variable_if")
6363
result (if (and (keyword? condi) (simlayers? condi))
6464
(do
65-
(if (and from to (not condi!?))
66-
(do
67-
(update-used-simlayers-config (condi (:simlayers conf-data)))
68-
(update-used-simlayers-config (assoc-in used-simlayers-config [:from :sim]
69-
(vec (conj (:sim (:from used-simlayers-config))
70-
(keyword (:key_code from))))))))
65+
(when (and from to (not condi!?))
66+
(update-used-simlayers-config (condi (:simlayers @conf-data)))
67+
(update-used-simlayers-config (assoc-in @used-simlayers-config [:from :sim]
68+
(vec (conj (:sim (:from @used-simlayers-config))
69+
(keyword (:key_code from)))))))
7170

7271
;; so that we can filter simlayer conditions in the
7372
;; none sim one and concat it into the sim one
@@ -76,8 +75,8 @@
7675
:type condi-type}
7776
{:simlayer condi}))
7877
result)
79-
result (if (and (keyword? condi) (nn? (or (condi (:layers conf-data))
80-
(condi layers))))
78+
result (if (and (keyword? condi) (some? (or (condi (:layers @conf-data))
79+
(condi layers))))
8180
(with-meta {:name (name condi)
8281
:value 1
8382
:type condi-type}
@@ -96,6 +95,6 @@
9695
:value 1
9796
:type condi-type}
9897
result)
99-
validate-result (massert (nn? result)
100-
(str "invalid condition keyword " condi ", can't find in any predefined conditions"))]]
98+
_validate-result (massert (some? result)
99+
(str "invalid condition keyword " condi ", can't find in any predefined conditions"))]]
101100
result))))

src/karabiner_configurator/core.clj

+39-43
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
11
(ns karabiner-configurator.core
22
(:require
33
[cheshire.core :as json]
4-
[clojure.string :as string]
54
[clojure.java.shell :as shell]
6-
[karabiner-configurator.modifiers :as modifiers]
7-
[karabiner-configurator.misc :refer :all]
8-
[karabiner-configurator.data :refer :all]
9-
[karabiner-configurator.layers :as layers]
5+
[clojure.string :as string]
6+
[clojure.tools.cli :as cli]
7+
[environ.core :refer [env]]
8+
[karabiner-configurator.data :as d]
109
[karabiner-configurator.froms :as froms]
11-
[karabiner-configurator.tos :as tos]
12-
[karabiner-configurator.rules :as rules]
10+
[karabiner-configurator.layers :as layers]
11+
[karabiner-configurator.misc :refer [load-edn load-json massert]]
12+
[karabiner-configurator.modifiers :as modifiers]
1313
[karabiner-configurator.profiles :as profiles]
14-
[clojure.edn :as edn]
15-
[me.raynes.fs :as fs]
16-
[clojure.tools.cli :as cli]
17-
[environ.core :refer [env]])
14+
[karabiner-configurator.rules :as rules]
15+
[karabiner-configurator.tos :as tos]
16+
[me.raynes.fs :as fs])
1817
(:gen-class))
1918

2019
;; helper function
2120
(defn update-static-conf
2221
"Helper function to update conf-data from reading rules"
2322
[key conf]
24-
(if (nn? conf)
25-
(assoc-conf-data key conf)))
23+
(when (some? conf)
24+
(d/assoc-conf-data key conf)))
2625

2726
(defn check-edn-syntax
2827
"Call joker to check syntax of karabiner.edn"
2928
[path]
30-
(let [;; intel mac
31-
joker-bin1 "/usr/local/opt/joker/bin/joker"
32-
;; arm mac
33-
joker-bin2 "/opt/homebrew/opt/joker/bin/joker"
34-
;; nix
35-
joker-bin3 (str (System/getenv "HOME") "/.nix-profile/bin/joker")
36-
;; fallback to which joker
37-
joker-bin (cond (fs/exists? joker-bin1) joker-bin1
38-
(fs/exists? joker-bin2) joker-bin2
39-
(fs/exists? joker-bin3) joker-bin3
40-
:else (-> (shell/sh "which" "joker")
41-
:out
42-
(string/trim-newline)
43-
(str "/bin/joker")))]
44-
(shell/sh joker-bin "--lint" path)))
29+
(let [sys-env (into {} (System/getenv))]
30+
(shell/sh "joker" "--lint" path
31+
:env (merge
32+
sys-env
33+
{"PATH"
34+
(str "/etc/profiles/per-user/" (System/getenv "USER") "/bin:" ;; nix profile
35+
"/run/current-system/sw/bin:" ;; nix darwin multiuser
36+
"/opt/homebrew/bin:" ;; arm homebrew
37+
"/usr/local/bin:" ;; homebrew
38+
(get sys-env "PATH"))}))))
4539

4640
(defn exit [status & [msg]]
47-
(if msg (println msg))
48-
(if (not (env :is-dev)) (System/exit status)))
41+
(when msg (println msg))
42+
(when-not (env :is-dev) (System/exit status)))
4943

5044
;; paths
5145
(defn json-config-file-path
@@ -73,17 +67,18 @@
7367
(defn parse-edn
7468
"Init conf data and return new rules based on karabiner.edn (main section in edn file)"
7569
[conf]
76-
(init-conf-data)
77-
(let [{:keys [applications devices keyboard-type input-sources tos froms modifiers layers simlayers raws main simlayer-threshold templates profiles]} conf]
70+
(d/init-conf-data)
71+
(let [{:keys [applications devices keyboard-type input-sources tos froms modifiers layers simlayers ;; raws
72+
main simlayer-threshold templates profiles]} conf]
7873
(if (nil? profiles)
79-
(profiles/parse-profiles (:profiles conf-data))
74+
(profiles/parse-profiles (:profiles d/conf-data))
8075
(profiles/parse-profiles profiles))
8176
(update-static-conf :applications applications)
8277
(update-static-conf :devices devices)
8378
(update-static-conf :keyboard-type keyboard-type)
8479
(update-static-conf :input-sources input-sources)
8580
(update-static-conf :templates templates)
86-
(if (number? simlayer-threshold)
81+
(when (number? simlayer-threshold)
8782
(update-static-conf :simlayer-threshold simlayer-threshold))
8883
(modifiers/parse-modifiers modifiers)
8984
(layers/parse-layers layers)
@@ -103,10 +98,10 @@
10398
(:profiles karabiner-config)]
10499
{(keyword (:name json-profile))
105100
json-profile}))]
106-
(doseq [[profile-k profile-v] customized-profiles]
101+
(doseq [[profile-k _] customized-profiles]
107102
(let [profile-name-str (name profile-k)]
108103
(massert
109-
(nn? (profile-k user-profiles))
104+
(some? (profile-k user-profiles))
110105
(format
111106
"Can't find profile named \"%s\" in karabiner.json, please create a profile named \"%s\" using the Karabiner-Elements.app."
112107
profile-name-str
@@ -143,17 +138,17 @@
143138
"Root function to parse karabiner.edn and update karabiner.json."
144139
[path & [dry-run dry-run-all]]
145140
(let [edn-syntax-err (:err (check-edn-syntax path))]
146-
(if (> (count edn-syntax-err) 0)
147-
(do (println "Syntax error in config:")
148-
(println edn-syntax-err)
149-
(exit 1))))
141+
(when (> (count edn-syntax-err) 0)
142+
(println "Syntax error in config:")
143+
(println edn-syntax-err)
144+
(exit 1)))
150145
(update-to-karabiner-json (parse-edn (load-edn path)) dry-run dry-run-all))
151146

152147
(defn open-log-file []
153148
(shell/sh "open" (log-file)))
154149
;; cli stuff
155150

156-
(defn help-message [options-summary]
151+
(defn help-message [_]
157152
(->> ["GokuRakuJoudo -- karabiner configurator"
158153
""
159154
"goku will read config file and update `Goku` profile in karabiner.json"
@@ -233,8 +228,9 @@
233228
;; main
234229
(defn -main
235230
[& args]
236-
(let [{:keys [action options exit-message ok? config dry-run dry-run-all]} (validate-args args)]
237-
(if exit-message
231+
(let [{:keys [action ;; options
232+
exit-message ok? config dry-run dry-run-all]} (validate-args args)]
233+
(when exit-message
238234
(case action
239235
"run" (do (parse (or config (edn-config-file-path)) dry-run dry-run-all)
240236
(exit (if ok? 0 1) exit-message))

0 commit comments

Comments
 (0)