diff --git a/.gitignore b/.gitignore index 832ad32..454d936 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,2 @@ *.pyc .directory -/scripts/bin/bbq -/scripts/bin/pkr -/pod/roswell/pod -/scripts/bin/pod -/scripts/bin/www -/scripts/bin/aux-backup -/scripts/bin/dump-commit-events -/scripts/bin/psc -/scripts/bin/patchwork - -/beets/.config/beets/state.pickle -/beets/.config/beets/discogs_token.json -/bbq/.config/bbq/scrobbled-at -*.sqlite diff --git a/pod/Lakefile b/pod/Lakefile deleted file mode 100644 index 3a975e8..0000000 --- a/pod/Lakefile +++ /dev/null @@ -1,45 +0,0 @@ -;;; -*- mode: lisp -*- - -(ql:quickload '(:trivia :serapeum :pod)) - -(defpackage #:lake.user - (:use #:cl #:lake #:cl-syntax) - (:shadowing-import-from #:lake :directory)) - -(in-package #:lake.user) -(use-syntax :interpol) - -(defun create-subcommand-script (cmd) - "Create script for subcommands." - (let ((file-name (serapeum:path-join #p"~/bin/" cmd))) - (with-open-file (fp file-name :direction :output - :if-exists :overwrite - :if-does-not-exist :create) - (write-string #?"#!/usr/bin/env fish\npod ${cmd} $argv" fp) - (sh #?"chmod +x ${file-name}")))) - -(defun setup-pod () - (let ((pod-file (truename #p"./roswell/pod"))) - (sh #?"rm -f ~/bin/pod") - (sh #?"ln -s ${pod-file} ~/bin/pod"))) - -(defun setup-cmd (cmd) - (let ((cmd-file (serapeum:path-join #p"~/bin/" cmd))) - (with-open-file (fp cmd-file :direction :output - :if-exists :overwrite - :if-does-not-exist :create) - (write-string #?"#!/usr/bin/env fish\npod ${cmd} $argv" fp) - (sh #?"chmod +x ${cmd-file}")))) - -(task "clean" () - (sh #?"rm -f ./roswell/pod")) - -(file "./roswell/pod" () - (sh #?"ros build ./roswell/pod.ros")) - -(task "build" ("./roswell/pod")) - -(task "setup" ("./roswell/pod") - (setup-pod) - (loop for pair in pod:*dispatches* - do (setup-cmd (car pair)))) diff --git a/pod/README.org b/pod/README.org deleted file mode 100644 index 0959e20..0000000 --- a/pod/README.org +++ /dev/null @@ -1,3 +0,0 @@ -#+TITLE: pod - -Scripts and default ~in-package~ for slime. diff --git a/pod/package.lisp b/pod/package.lisp deleted file mode 100644 index bf181d7..0000000 --- a/pod/package.lisp +++ /dev/null @@ -1,28 +0,0 @@ -;;;; package.lisp - -(defpackage #:pod - (:use #:cl - #:alexandria - #:anaphora - #:serapeum - #:cl-strings - #:cl-arrows - #:cl-ppcre - #:cl-cut - #:cl-interpol - #:inferior-shell - #:lparallel - #:trivia) - (:shadowing-import-from #:anaphora - :slet) - (:shadowing-import-from #:cl-strings - :starts-with :ends-with :parse-number :split) - (:shadowing-import-from #:cl-arrows - :->) - (:shadowing-import-from #:serapeum - :scan :@) - (:shadowing-import-from #:inferior-shell - :fork) - (:shadowing-import-from #:trivia - :<>) - (:export #:*dispatches*)) diff --git a/pod/pod.asd b/pod/pod.asd deleted file mode 100644 index a658278..0000000 --- a/pod/pod.asd +++ /dev/null @@ -1,24 +0,0 @@ -;;;; pod.asd - -(defsystem #:pod - :description "Scripts in common lisp" - :author "Abhinav Tushar " - :license "GPLv3" - :depends-on (#:alexandria - #:anaphora - #:serapeum - #:cl-strings - #:cl-arrows - #:cl-ppcre - #:cl-cut - #:cl-interpol - #:inferior-shell - #:local-time - #:lparallel - #:parenscript - #:spinneret - #:trivia - #:uiop) - :serial t - :components ((:file "package") - (:file "pod"))) diff --git a/pod/pod.lisp b/pod/pod.lisp deleted file mode 100644 index 8fff747..0000000 --- a/pod/pod.lisp +++ /dev/null @@ -1,128 +0,0 @@ -;;;; pod.lisp - -(in-package #:pod) -(enable-interpol-syntax) - -(defparameter *browser* "firefox" - "Main browser") - -(defparameter *alt-browser* "chromium" - "Alternate browser") - -(defparameter *dispatches* - '(("www" . www) - ("aux-backup" . aux-backup) - ("dump-commit-events" . dump-commit-events)) - "Mapping from command to functions.") - -(defparameter *www-dispatches* - `((".google\.co" . ,*alt-browser*) - ("metabase\.skit" . ,*alt-browser*) - ("^file:///*" . ,*alt-browser*) - ("outline\.skit" . ,*alt-browser*)) - "Patterns for handling url based dispatches.") - -(defun www (&rest args) - "Open browser based on url pattern matches." - (if (null args) - (uiop:launch-program *browser*) - (unless - (loop for pattern in *www-dispatches* - if (ppcre:scan (car pattern) (car args)) - do (return (uiop:launch-program (list (cdr pattern) (car args))))) - (uiop:launch-program (list *browser* (car args)))))) - -;;; Git analysis stuff - -(defparameter *git-author* "Abhinav Tushar" - "Author name to look for in git logs.") - -(defparameter *repos-dirs* (list #p"~/.tofish/p/" - #p"~/cfg" - #p"~/Desktop" - #p"~/.tofish/r") - "Directories where git repositories might be present.") - -(defun git-repos-in-dir (dir-path) - "Return a list of git repositories" - (let ((find-out (run/s `(find "-L" ,dir-path -name "\*.git" -type d)))) - (mapcar #'pathname-directory (split (trim-whitespace find-out) #\linefeed)))) - -(defun git-repos () - "Return all git repositories." - (reduce #'append (mapcar #'git-repos-in-dir *repos-dirs*))) - -(defun repo-commit-events (path-spec) - "Return a list of commit events (times) for the repo." - (uiop:call-with-current-directory - (make-pathname :directory path-spec) - (lambda () - (let ((log-out (trim-whitespace (run/s `(git log --all --author ,*git-author* "--pretty=format:%at"))))) - (unless (string-equal "" log-out) - (mapcar (compose #'local-time:unix-to-timestamp #'parse-integer) (split log-out #\linefeed))))))) - -(defun format-commit-line (timestamp) - (multiple-value-bind (year week day) (local-time::%timestamp-decode-iso-week timestamp) - (format nil "~A,~A-~2,'0d" (local-time:timestamp-to-unix timestamp) year week))) - -(defun parse-commit-line (line) - "Return timestamp from commit event line." - (let ((text (trim-whitespace (car (split line ","))))) - (local-time:unix-to-timestamp (parse-integer text)))) - -(defun commit-events () - "Return all the local commit events" - (-<> (git-repos) - (mapcar #'repo-commit-events <>) - (reduce #'append <>) - (sort #'local-time:timestamp<) - (remove-duplicates :test #'local-time:timestamp=))) - -(defun read-commit-events (file-path) - "Read commit events as list of timestamps from the given csv path." - (when (probe-file file-path) - (-<> (read-file-into-string file-path) - trim-whitespace - (split #\linefeed) - cdr - (mapcar #'parse-commit-line <>) - (sort #'local-time:timestamp<) - (remove-duplicates :test #'local-time:timestamp=)))) - -(defun merge-commit-events (events-a events-b) - "Merge events from a and b lists." - (remove-duplicates (sort (append events-a events-b) #'local-time:timestamp<) :test #'local-time:timestamp=)) - -(defun dump-commit-events (&rest args) - (let* ((f-name (or (car args) "./commit-events.csv")) - (old-events (read-commit-events f-name)) - (separator (make-string 1 :initial-element #\linefeed)) - (header "timestamp,week") - (new-events (commit-events)) - (lines (mapcar #'format-commit-line (merge-commit-events old-events new-events)))) - (write-string-into-file (join (cons header lines) :separator separator) f-name :if-exists :supersede - :if-does-not-exist :create))) - -;;; Aux backup stuff - -(defparameter *aux-backup-dirs* (list #p"~/.tofish/d/Vault" - #p"~/.tofish/d/Documents" - #p"~/.tofish/d/Notes" - #p"~/Zotero" - #p"~/.config/bbq") - "Directories to backup on secondary cloud.") - -(defun backup (dirs outdir outfile) - (let* ((encrypted (concat outfile ".gpg"))) - (uiop:call-with-current-directory - (uiop:temporary-directory) - (lambda () - (princ #?"Backing up ${dirs}\n") - (run/s `(tar czf ,outfile --exclude=pdfs/* ,@dirs)) - (run/s `(gpg --symmetric ,outfile)) - (run/s `(rm ,outfile)) - (run/s `(mv ,encrypted ,(path-join outdir encrypted))) - (princ #?"File ${encrypted} saved in ${outdir}\n"))))) - -(defun aux-backup () - (backup *aux-backup-dirs* #p"~/.tofish/c/" "aux-backup.tar.gz")) diff --git a/pod/roswell/pod.ros b/pod/roswell/pod.ros deleted file mode 100755 index d8f0348..0000000 --- a/pod/roswell/pod.ros +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -#|-*- mode:lisp -*-|# -#| -exec ros -Q -- $0 "$@" -|# - -(ql:quickload '(:pod :trivia :serapeum) :silent t) - -(defpackage :ros.script.pod.3747827678 - (:use #:cl #:trivia)) -(in-package :ros.script.pod.3747827678) - -(defun main (&rest argv) - (match argv - ((list* sub-command args) - (let ((fn (serapeum:assocdr sub-command pod:*dispatches* :test #'string-equal))) - (if fn (apply fn args) (princ "pod subcommand not found")))) - (_ (princ "usage: pod []")))) diff --git a/scripts/bin/www b/scripts/bin/www new file mode 100755 index 0000000..63ac7a9 --- /dev/null +++ b/scripts/bin/www @@ -0,0 +1,17 @@ +#!/usr/bin/env fish + +# Usage: +# www ... + +set -l app "firefox" + +set -l alt_patterns ".google.co" "metabase.skit" + +for pattern in $alt_patterns + if test -n (string match -r $pattern $argv[1]) + set app "chromium" + break + end +end + +eval $app $argv