-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresumetask.clj
executable file
·57 lines (54 loc) · 2.04 KB
/
resumetask.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bb
(require '[clojure.string :as str]
'[clojure.java.io :as io]
'[clojure.java.shell :as sh])
(defn get-taskwarrior-data-location []
(let [home (System/getProperty "user.home")
taskrc (-> (try (slurp (str home "/.taskrc"))
(catch Exception _
(slurp (str home "/.config/task/taskrc"))))
(as-> rc (str/split rc #"\n")))
;On NixOS or using Homemanager, the taskrc may be
;in another place. The following lines tries to find
;that place.
config (-> taskrc
(as-> lines
(filter #(str/includes? % "include") lines))
(as-> lines
(map #(drop 8 %) lines))
(as-> lines
(map #(str/join "" %) lines))
(as-> paths
(map #(slurp %) paths))
(as-> lines
(map #(str/split % #"\n") lines))
(flatten)
(concat taskrc))
datalocation (-> config
(as-> c
(filter #(str/includes? % "data.location") c))
(first)
(as-> line (drop 14 line))
(as-> ch (str/join "" ch))
(str/replace "~" home))]
datalocation))
(defn validate-task
"Validate if task is not complete"
[uuid]
(if (-> (sh/sh "taskinfo" uuid "status")
(:out)
(str/replace "\n" "")
(= "completed"))
(do (println "Task is already completed.")
(System/exit 1))
uuid))
(let [data-path (get-taskwarrior-data-location)
modified-path (str data-path "/last-modified.data")]
(when-not (.exists (io/file modified-path))
(println "No last modified data. Have you installed and used the hook?")
(System/exit 1))
(-> (slurp modified-path)
(validate-task)
(as-> id (sh/sh "task" id "start"))
(:out)
(println)))