Created
October 19, 2020 17:46
-
-
Save lispyclouds/d21235724145efe3c97d92a699b1cdce to your computer and use it in GitHub Desktop.
Removes dupes from ZSH history, preserving timestamps. Compatible with babashka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.java.io :as io] | |
'[clojure.string :as s]) | |
(defn line->cmd | |
[line] | |
^String | |
(some->> (s/index-of line \;) | |
inc | |
(subs line))) | |
(with-open [rdr (io/reader (str (System/getProperty "user.home") "/.zsh_history"))] | |
(let [lines (loop [[line & lines] (line-seq rdr) | |
uniq-cmds (transient #{}) | |
uniq-lines (transient [])] | |
#_(println (format "Remaining: %d Unique: %d" | |
(count lines) | |
(count uniq-cmds))) | |
(if (nil? line) | |
(persistent! uniq-lines) | |
(let [cmd (line->cmd line)] | |
(if (uniq-cmds cmd) | |
(recur lines uniq-cmds uniq-lines) | |
(recur lines (conj! uniq-cmds cmd) (conj! uniq-lines line))))))] | |
(doseq [line lines] | |
(println line)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment