Skip to content

Commit

Permalink
ag-scaladef, ag-tsdef
Browse files Browse the repository at this point in the history
  • Loading branch information
ne-sachirou committed Nov 22, 2021
1 parent 24107e3 commit 74d6e66
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 38 deletions.
2 changes: 1 addition & 1 deletion roles/zsh/files/bin/.cljstyle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:files {:pattern #"^(agperl|docker-gc|etags-of|git-gone|mackerel-plugin-speedtest)$"}}
{:files {:pattern #"^(agperl|ag-scaladef|ag-tsdef|docker-gc|etags-of|git-gone|mackerel-plugin-speedtest)$"}}
14 changes: 14 additions & 0 deletions roles/zsh/files/bin/ag-scaladef
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bb
;; -*- mode: clojure; -*-
(require '[babashka.process :refer [process]])


;; ag -G '\.scala$' "(class|def|object|trait|type|val|var) $1(?=\W)"
(-> ["ag"
"-G" "\\.scala$"
"--color"
(str "(class|def|object|trait|type|val|var) " (first *command-line-args*) "(?=\\W)")]
(process {:in :inherit})
:out
slurp
println)
14 changes: 14 additions & 0 deletions roles/zsh/files/bin/ag-tsdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bb
;; -*- mode: clojure; -*-
(require '[babashka.process :refer [process]])


;; ag -G '(?<!\.test)\.ts(x?)$' "(class|const|function|interface|let|type|var|(^ *)) $1"
(-> ["ag"
"-G" "(?<!\\.test)\\.ts(x?)$"
"--color"
(str "(class|const|function|interface|let|type|var|(^ *)) " (first *command-line-args*))]
(process {:in :inherit})
:out
slurp
println)
4 changes: 2 additions & 2 deletions roles/zsh/files/bin/agperl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bb
; -*- mode: clojure; -*-
;; -*- mode: clojure; -*-
(require '[babashka.process :refer [process]])


Expand All @@ -18,7 +18,7 @@
(filter #(not= "" %) (-> proc :out slurp str/split-lines))))


; ag -l "$1" | xargs -I{} -t perl -pi -e"s/$1/$2/g" {}
;; ag -l "$1" | xargs -I{} -t perl -pi -e"s/$1/$2/g" {}
(let [[match replacement] *command-line-args*
filenames (ag-l match)]
(doseq [filename filenames]
Expand Down
40 changes: 20 additions & 20 deletions roles/zsh/files/bin/docker-gc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bb
; -*- mode: clojure; -*-
;; -*- mode: clojure; -*-

(defn sh
[& args]
Expand All @@ -10,7 +10,7 @@
out))


; docker image ls --format "{{.Repository}}:{{.Tag}}" | tail -n +2 | xargs -t -I{} docker pull {}
;; docker image ls --format "{{.Repository}}:{{.Tag}}" | tail -n +2 | xargs -t -I{} docker pull {}
(defn update-images
[]
(doseq [image (->> (sh "docker" "image" "ls" "--format" "{{.Repository}}:{{.Tag}}")
Expand All @@ -20,36 +20,36 @@
(and (not (str/includes? line "<none>"))
(not (str/starts-with? line "k8s.gcr.io/"))
(not (str/starts-with? line "docker/"))
; WARNING: ⚠️ Failed to pull manifest by the resolved digest. This registry does not appear to conform to the distribution registry specification; falling back to pull by tag. This fallback is DEPRECATED, and will be removed in a future release. Please contact admins of https://docker.pkg.github.com. ⚠️
;; WARNING: ⚠️ Failed to pull manifest by the resolved digest. This registry does not appear to conform to the distribution registry specification; falling back to pull by tag. This fallback is DEPRECATED, and will be removed in a future release. Please contact admins of https://docker.pkg.github.com. ⚠️
(not (str/starts-with? line "docker.pkg.github.com/"))))))]
(try
(sh "docker" "pull" image)
(catch Exception err (println (.getMessage err))))))


; docker image prune -af --filter "until=2160h"
; (defn prune-old-images
; []
; (doseq [[image _created-since] (->> (sh "docker" "image" "ls" "--format" "{{.Repository}}:{{.Tag}}\t{{.CreatedSince}}")
; str/split-lines
; (drop 1)
; (map (fn [line]
; (let [[image created-since-str] (str/split line #"\t")
; [number unit] (take 2 (str/split created-since-str #" "))]
; [image {:number number :unit unit}])))
; (filter (fn [[image {:keys [number unit]}]]
; (and (not (str/starts-with? image "k8s.gcr.io/"))
; (not (str/starts-with? image "docker/"))
; (= "years" unit)
; (and (= "months" unit) (>= 6 number))))))]
; (sh "docker" "image" "rm" "-f" image)))
;; docker image prune -af --filter "until=2160h"
;; (defn prune-old-images
;; []
;; (doseq [[image _created-since] (->> (sh "docker" "image" "ls" "--format" "{{.Repository}}:{{.Tag}}\t{{.CreatedSince}}")
;; str/split-lines
;; (drop 1)
;; (map (fn [line]
;; (let [[image created-since-str] (str/split line #"\t")
;; [number unit] (take 2 (str/split created-since-str #" "))]
;; [image {:number number :unit unit}])))
;; (filter (fn [[image {:keys [number unit]}]]
;; (and (not (str/starts-with? image "k8s.gcr.io/"))
;; (not (str/starts-with? image "docker/"))
;; (= "years" unit)
;; (and (= "months" unit) (>= 6 number))))))]
;; (sh "docker" "image" "rm" "-f" image)))


(defn -main
[]
(sh "docker" "system" "prune" "-f" "--volumes")
(update-images)
; (prune-old-images)
;; (prune-old-images)
(sh "docker" "run" "--rm" "--privileged" "alpine:latest" "hwclock" "-s"))


Expand Down
6 changes: 3 additions & 3 deletions roles/zsh/files/bin/etags-of
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bb
; -*- mode: clojure; -*-
;; -*- mode: clojure; -*-
(require '[babashka.process :refer [process]])


Expand All @@ -20,11 +20,11 @@

(defn -main
[]
; rm -vf TAGS
;; rm -vf TAGS
(if (.exists (io/file "TAGS"))
(io/delete-file "TAGS")
:ok)
; ag -g '\.(c|cpp|erl|h|hrl|java|php|pl|py|rb|tex|y)$' | xargs -t etags -a
;; ag -g '\.(c|cpp|erl|h|hrl|java|php|pl|py|rb|tex|y)$' | xargs -t etags -a
(let [filenames (ag-g "\\.(c|cpp|erl|h|hrl|java|php|pl|py|rb|tex|y)$")]
(doseq [filenames (partition-all 101 filenames)]
(try
Expand Down
12 changes: 7 additions & 5 deletions roles/zsh/files/bin/git-gone
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bb
; -*- mode: clojure; -*-
;; -*- mode: clojure; -*-

(ns util
(:require
Expand All @@ -26,8 +26,9 @@


(ns git
(:require [clojure.string :as str]
util))
(:require
[clojure.string :as str]
[util]))


(defn branch-
Expand Down Expand Up @@ -118,8 +119,9 @@


(ns user
(:require git
util))
(:require
[git]
[util]))


(defn delete-local-merged-branches
Expand Down
16 changes: 9 additions & 7 deletions roles/zsh/files/bin/mackerel-plugin-speedtest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bb
; -*- mode: clojure; -*-
;; -*- mode: clojure; -*-

(ns metric
(:require
Expand All @@ -20,10 +20,11 @@


(ns speedtest
(:require [cheshire.core :as json]
[clojure.java.shell :as shell]
[clojure.string :as str]
metric))
(:require
[cheshire.core :as json]
[clojure.java.shell :as shell]
[clojure.string :as str]
[metric]))


(def cache-filename
Expand Down Expand Up @@ -69,8 +70,9 @@


(ns user
(:require metric
speedtest))
(:require
[metric]
[speedtest]))


(defn print-meta
Expand Down

0 comments on commit 74d6e66

Please sign in to comment.