7834451ffb31

Merge.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 11 Nov 2019 20:45:45 -0500
parents b83a98ba30ee (diff) e3f46c421f0e (current diff)
children 5a3902856597
branches/tags (none)
files

Changes

--- a/bin/eq-dotcount	Fri Oct 18 16:50:19 2019 -0400
+++ b/bin/eq-dotcount	Mon Nov 11 20:45:45 2019 -0500
@@ -1,3 +1,3 @@
 #!/usr/bin/env bash
 
-grep -Eo 'has taken \d+ damage from your' | cut -d' ' -f3 | awk '{s+=$1} END {print s}' -
+grep -Eo 'has taken \d+ damage from your' | awk '{s+=$3} END {print s}' -
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/.lispwords	Mon Nov 11 20:45:45 2019 -0500
@@ -0,0 +1,1 @@
+(1 maybe-die-on-errors)
--- a/lisp/batchcolor.lisp	Fri Oct 18 16:50:19 2019 -0400
+++ b/lisp/batchcolor.lisp	Mon Nov 11 20:45:45 2019 -0500
@@ -9,6 +9,7 @@
 
 ;;;; Configuration ------------------------------------------------------------
 (defparameter *version* "0.0.1")
+(defparameter *start* 0)
 
 (defun rgb-code (r g b)
   ;; The 256 color mode color values are essentially r/g/b in base 6, but
@@ -38,7 +39,7 @@
           :key #'char-code))
 
 (defun find-color (string)
-  (aref *colors* (mod (djb2 string)
+  (aref *colors* (mod (+ (djb2 string) *start*)
                       (length *colors*))))
 
 (defun ansi-color-start (color)
@@ -65,11 +66,19 @@
 
 
 ;;;; Run ----------------------------------------------------------------------
-(defun run (pattern)
-  (loop
-    :with scanner = (ppcre:create-scanner pattern)
-    :for line = (read-line *standard-input* nil)
-    :while line :do (colorize-line scanner line)))
+(defun run% (scanner stream)
+  (loop :for line = (read-line stream nil)
+        :while line :do (colorize-line scanner line)))
+
+(defun run (pattern paths)
+  (if (null paths)
+    (setf paths '("-")))
+  (let ((scanner (ppcre:create-scanner pattern)))
+    (dolist (path paths)
+      (if (string= "-" path)
+        (run% scanner *standard-input*)
+        (with-open-file (stream path :direction :input)
+          (run% scanner stream))))))
 
 
 ;;;; User Interface -----------------------------------------------------------
@@ -80,6 +89,36 @@
      . "tail -f /var/log/foo | batchcolor '([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})'")))
 
 
+(defparameter *option-randomize*
+  (adopt:make-option 'randomize
+    :help "Randomize the choice of color each run."
+    :long "randomize"
+    :short #\r
+    :reduce (constantly t)))
+
+(defparameter *option-no-randomize*
+  (adopt:make-option 'no-randomize
+    :result-key 'randomize
+    :help "Do not randomize the choice of color each run (the default)."
+    :long "no-randomize"
+    :short #\R
+    :reduce (constantly nil)))
+
+(defparameter *option-debug*
+  (adopt:make-option 'debug
+    :help "Enable the lisp debugger."
+    :long "debug"
+    :short #\d
+    :reduce (constantly t)))
+
+(defparameter *option-no-debug*
+  (adopt:make-option 'no-debug
+    :result-key 'debug
+    :help "Disable the lisp debugger (the default)."
+    :long "no-debug"
+    :short #\D
+    :reduce (constantly nil)))
+
 (defparameter *option-help*
   (adopt:make-option 'help
     :help "Display help and exit."
@@ -102,29 +141,54 @@
 (defparameter *ui*
   (adopt:make-interface
     :name "batchcolor"
-    :usage "[OPTIONS] REGEX"
+    :usage "[OPTIONS] REGEX [FILE...]"
     :summary "colorize regex matches in batches"
     :help *help-text*
     :examples *examples*
-    :contents (list *option-help*
+    :contents (list *option-randomize*
+                    *option-no-randomize*
+                    *option-debug*
+                    *option-no-debug*
+                    *option-help*
                     *option-version*)))
 
 
-(defun toplevel ()
+(defmacro quit-on-ctrl-c (&body body)
+  `(handler-case
+     (progn ,@body)
+     #+sbcl (sb-sys:interactive-interrupt (c)
+               (declare (ignore c))
+               (adopt:exit))))
+
+(defmacro maybe-die-on-errors (should-die &body body)
+  `(if ,should-die
+     (handler-case (progn ,@body)
+       (error (c) (adopt:print-error-and-exit c)))
+     (progn
+       #+sbcl (sb-ext:enable-debugger)
+       ,@body)))
+
+(defun parse-options-or-exit (ui)
+  (handler-case (adopt:parse-options ui)
+    (error (c) (adopt:print-error-and-exit c))))
+
+
+(defun toplevel (&aux arguments options)
   #+sbcl (sb-ext:disable-debugger)
-  (handler-case
-      (multiple-value-bind (arguments options) (adopt:parse-options *ui*)
-        (when (gethash 'help options)
-          (adopt:print-help-and-exit *ui*))
-        (when (gethash 'version options)
-          (write-line *version*)
-          (adopt:exit))
-        (if (/= 1 (length arguments))
-          (adopt:print-help-and-exit *ui*)
-          (destructuring-bind (pattern) arguments
-            (run pattern))))
-    (error (c) (adopt:print-error-and-exit c))
-    #+sbcl (sb-sys:interactive-interrupt (c)
-             (declare (ignore c))
-             (adopt:exit))))
+  (quit-on-ctrl-c
+    (setf (values arguments options)
+          (parse-options-or-exit *ui*))
+    (maybe-die-on-errors (not (gethash 'debug options))
+      (when (gethash 'help options)
+        (adopt:print-help-and-exit *ui*))
+      (when (gethash 'version options)
+        (write-line *version*)
+        (adopt:exit))
+      (if (< (length arguments) 1)
+        (adopt:print-help-and-exit *ui*)
+        (destructuring-bind (pattern . files) arguments
+          (let ((*start* (if (gethash 'randomize options)
+                           (random 256 (make-random-state t))
+                           0)))
+            (run pattern files)))))))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/json-string.lisp	Mon Nov 11 20:45:45 2019 -0500
@@ -0,0 +1,113 @@
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (ql:quickload '(:adopt :yason :alexandria) :silent t))
+
+(defpackage :json-string
+  (:use :cl)
+  (:export :toplevel :*ui*))
+
+(in-package :json-string)
+
+;;;; Configuration ------------------------------------------------------------
+(defparameter *version* "0.0.1")
+
+
+;;;; Functionality ------------------------------------------------------------
+(defun stringify (stream)
+  (yason:encode
+    (alexandria:read-stream-content-into-string stream)
+    *standard-output*))
+
+
+;;;; Run ----------------------------------------------------------------------
+(defun run (paths)
+  (if (null paths)
+    (setf paths '("-")))
+  (dolist (path paths)
+    (fresh-line)
+    (if (string= "-" path)
+      (stringify *standard-input*)
+      (with-open-file (stream path :direction :input)
+        (stringify stream)))))
+
+
+;;;; User Interface -----------------------------------------------------------
+(defparameter *examples*
+  '(("Stringify standard input:" . "echo 'foo and bar' | json-string")
+    ("Turn 3 files into 3 strings:" . "json-string foo bar baz")
+    ("Turn 3 files into one big string:" . "cat foo bar baz | json-string")))
+
+
+(defparameter *option-debug*
+  (adopt:make-option 'debug
+    :help "Enable the lisp debugger."
+    :long "debug"
+    :short #\d
+    :reduce (constantly t)))
+
+(defparameter *option-no-debug*
+  (adopt:make-option 'no-debug
+    :result-key 'debug
+    :help "Disable the lisp debugger (the default)."
+    :long "no-debug"
+    :short #\D
+    :reduce (constantly nil)))
+
+(defparameter *option-help*
+  (adopt:make-option 'help
+    :help "Display help and exit."
+    :long "help"
+    :short #\h
+    :reduce (constantly t)))
+
+(defparameter *option-version*
+  (adopt:make-option 'version
+    :help "Display version information and exit."
+    :long "version"
+    :reduce (constantly t)))
+
+
+(adopt:define-string *help-text*
+  "json-string takes a stream of data (either standard input or a file) and ~
+   renders its content into a JSON string, suitable for copying and pasting ~
+   into a JSON file.  If multiple files are specified, they will each be ~
+   converted into a string and printed one per line.")
+
+(defparameter *ui*
+  (adopt:make-interface
+    :name "json-string"
+    :usage "[OPTIONS] [FILE...]"
+    :summary "render content as a JSON string"
+    :help *help-text*
+    :examples *examples*
+    :contents (list *option-help*
+                    *option-version*)))
+
+
+(defmacro quit-on-ctrl-c (&body body)
+  `(handler-case
+     (progn ,@body)
+     #+sbcl (sb-sys:interactive-interrupt (c)
+               (declare (ignore c))
+               (adopt:exit))))
+
+
+(defun parse-options-or-exit (ui)
+  (handler-case (adopt:parse-options ui)
+    (error (c) (adopt:print-error-and-exit c))))
+
+
+(defun toplevel (&aux arguments options)
+  #+sbcl (sb-ext:disable-debugger)
+  (quit-on-ctrl-c
+    (setf (values arguments options)
+          (parse-options-or-exit *ui*))
+    (handler-case
+        (progn
+          (when (gethash 'help options)
+            (adopt:print-help-and-exit *ui*))
+          (when (gethash 'version options)
+            (write-line *version*)
+            (adopt:exit))
+          (run arguments))
+      (error (c) (adopt:print-error-and-exit c)))))
+
--- a/sbclrc	Fri Oct 18 16:50:19 2019 -0400
+++ b/sbclrc	Mon Nov 11 20:45:45 2019 -0500
@@ -19,3 +19,8 @@
 (defun :fg ()
   (sb-thread:release-foreground))
 
+
+(defmacro := (var val)
+  `(progn
+     (defglobal ,var nil)
+     (setf ,var ,val)))
--- a/stumpwmrc	Fri Oct 18 16:50:19 2019 -0400
+++ b/stumpwmrc	Mon Nov 11 20:45:45 2019 -0500
@@ -293,8 +293,7 @@
         for (output commands) in `((,laptop ("--auto"))
                                    (,laptop ("--primary"))
                                    (,extern ("--off")))
-        do (progn (uiop:run-program `("xrandr" "--output" ,output ,@commands))
-                  (sleep 1))))
+        do (progn (uiop:run-program `("xrandr" "--output" ,output ,@commands)))))
 
 (defcommand screen-external () ()
   (only)
@@ -302,9 +301,11 @@
         with extern = "DP1"
         for (output commands) in `((,extern ("--auto"))
                                    (,extern ("--primary"))
-                                   (,laptop ("--off")))
-        do (progn (uiop:run-program `("xrandr" "--output" ,output ,@commands))
-                  (sleep 1))))
+                                   ;; (,laptop ("--off"))
+                                   (,laptop ("--auto"))
+                                   (,laptop ("--right-of" ,extern))
+                                   )
+        do (uiop:run-program `("xrandr" "--output" ,output ,@commands))))
 
 (defcommand vlime () ()
   (load "~/src/dotfiles/vim/bundle/vlime/lisp/start-vlime.lisp")
--- a/vim/vimrc	Fri Oct 18 16:50:19 2019 -0400
+++ b/vim/vimrc	Mon Nov 11 20:45:45 2019 -0500
@@ -482,8 +482,12 @@
 imap <c-l> <c-o>gi
 
 " Diff Navigation
-nnoremap dn ]c
-nnoremap dN [c
+nnoremap ]d ]c
+nnoremap [d [c
+
+" Typo navigation
+nnoremap ]z ]S
+nnoremap [z [S
 
 " Insert Mode Completion {{{
 
@@ -1488,6 +1492,8 @@
 augroup ft_go
     au!
 
+    au BufRead,BufNewFile go.mod set ft=go
+
     au FileType go setlocal shiftwidth=8
     au FileType go setlocal foldmethod=expr
     au FileType go setlocal foldexpr=GetGoFold(v:lnum)
@@ -1693,6 +1699,7 @@
     au Filetype markdown nnoremap <buffer> <localleader>4 mzI####<space><esc>`zlllll
 
     au Filetype markdown inoremap <buffer> <c-cr> <cr><esc>mz?^ *\*?e<cr>"zy0:noh<cr>`z"zpA* <esc>a
+    au Filetype markdown inoremap <buffer> <s-c-cr> <cr><esc>mz?^ *\*?e<cr>"zy0:noh<cr>`z"zpA  * <esc>a
     au Filetype markdown inoremap <buffer> <s-tab> <esc>mz0xx`za
     au Filetype markdown inoremap <buffer> <c-tab> <esc>mzI  <esc>`zlla
 augroup END
@@ -2013,6 +2020,14 @@
 augroup END
 
 " }}}
+" Terminal {{{
+
+augroup ft_terminal
+    au!
+    au TermOpen * setlocal scrolloff=0
+augroup END
+
+" }}}
 " Vagrant {{{
 
 augroup ft_vagrant
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/weechat/python/autoload/brows.py	Mon Nov 11 20:45:45 2019 -0500
@@ -0,0 +1,77 @@
+import subprocess
+import os
+
+SCRIPT_NAME = 'brows'
+SCRIPT_AUTHOR = 'Steve Losh <steve@stevelosh.com>'
+SCRIPT_VERSION = '1.0'
+SCRIPT_LICENSE = 'MIT/X11'
+SCRIPT_DESC = 'Launch brows to view URLs'
+SCRIPT_COMMAND = 'brows'
+
+import_ok = True
+
+BROWS = os.environ.get('BROWS', 'brows')
+
+try:
+    import weechat
+except ImportError:
+    print 'This is a weechat script, what are you doing, run it in weechat, jesus'
+    import_ok = False
+
+weechat_version = 0
+
+def hd(fn, name, obj, attr):
+    return fn(weechat.hdata_get(name), obj, attr)
+
+def hdp(name, obj, attr):
+    return hd(weechat.hdata_pointer, name, obj, attr)
+
+def hds(name, obj, attr):
+    return hd(weechat.hdata_string, name, obj, attr)
+
+def get_lines(buffer, numlines):
+    lines = hdp("buffer", buffer, "own_lines")
+    if not lines:
+        # null pointer wat do
+        return None
+
+    last_lines = []
+
+    line = hdp("lines", lines, "last_line")
+    for _ in range(numlines):
+        if not line:
+            # shit we're at the top of the buffer
+            break
+
+        data = hdp("line", line, "data")
+        msg = hds("line_data", data, "message")
+        msg = weechat.string_remove_color(msg, "")
+
+        last_lines.append(msg.strip())
+
+        line = hdp("line", line, "prev_line")
+
+    return last_lines
+
+def brows(data, buffer, args, numlines=100):
+    lines = get_lines(buffer, numlines)
+
+    proc = subprocess.Popen([BROWS], stdin=subprocess.PIPE)
+    proc.communicate(input='\n'.join(lines))
+    weechat.command("", "/window refresh")
+
+    return weechat.WEECHAT_RC_OK
+
+
+if __name__ == '__main__' and import_ok:
+    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
+                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
+        weechat_version = weechat.info_get('version_number', '') or 0
+        weechat.hook_command(
+            SCRIPT_COMMAND,
+            'Launch brows to view URLs',
+            '',
+            '',
+            '',
+            'brows',
+            '')
--- a/weechat/weechat.conf	Fri Oct 18 16:50:19 2019 -0400
+++ b/weechat/weechat.conf	Mon Nov 11 20:45:45 2019 -0500
@@ -353,7 +353,7 @@
 [key]
 ctrl-? = "/input delete_previous_char"
 ctrl-A = "/input move_beginning_of_line"
-ctrl-B = "/input move_previous_char"
+ctrl-B = "/brows"
 ctrl-Cb = "/input insert \x02"
 ctrl-Cc = "/input insert \x03"
 ctrl-Ci = "/input insert \x1D"