Added commands.

Pascal J. Bourguignon [2018-03-31 18:40]
Added commands.
Filename
capitalize
dedup
macosx-port-reinstall
diff --git a/capitalize b/capitalize
new file mode 100755
index 0000000..2564e46
--- /dev/null
+++ b/capitalize
@@ -0,0 +1,43 @@
+#!/usr/local/bin/clisp -ansi -q -on-error debug
+;;;; -*- mode:lisp -*-
+
+
+;; Replaces any sequences of non alphanumeric or dot character in the
+;; arguments by a single dash.
+
+(defun split-string-if (predicate string &key remove-empty-subseqs)
+  "
+NOTE:   current implementation only accepts as separators
+        a string containing literal characters.
+"
+  (let ((chunks  '())
+        (position 0)
+        (nextpos  0)
+        (strlen   (length string)))
+    (loop :while (< position strlen) :do
+       (loop :while (and (< nextpos strlen)
+                         (not (funcall predicate (aref string nextpos)))) :do
+          (incf nextpos))
+       (push (subseq string position nextpos) chunks)
+       (setf position (1+ nextpos)
+             nextpos  position))
+    (nreverse chunks)))
+
+(defun split-string (separators string &key remove-empty-subseqs)
+  (split-string-if (lambda (ch) (find ch separators)) string
+                   :remove-empty-subseqs remove-empty-subseqs))
+
+
+;;;;--------------------------------------------------------------------
+
+(defun main (args)
+  (loop
+    :for arg :in args
+    :do (write-line (string-capitalize arg)))
+  0)
+
+
+#-testing-script
+(ext:exit (main ext:*args*))
+
+;;;;--------------------------------------------------------------------
diff --git a/dedup b/dedup
new file mode 100755
index 0000000..b8f1e92
--- /dev/null
+++ b/dedup
@@ -0,0 +1,28 @@
+#!/usr/local/bin/clisp -norc -ansi -q -E utf-8
+
+(load #P"~/quicklisp/setup.lisp")
+(ql:quickload :com.informatimago.common-lisp.cesarum)
+(use-package :com.informatimago.common-lisp.cesarum.stream)
+(use-package :com.informatimago.common-lisp.cesarum.utility)
+
+(defun main ()
+ (let* ((lines (stream-to-string-list *standard-input*))
+        (table (make-hash-table :test 'equal)))
+   (loop :for (k v)
+           :in (mapcar (lambda (line)
+                         (let ((p (search "  " line)))
+                           (list (subseq line 0 p)
+                                 (subseq line (+ 2 p)))))
+                       lines)
+         :do (push v (gethash k table '())))
+   (maphash (lambda (k vs)
+              (unless (cdr vs)
+                (remhash k table)))
+            table)
+   (maphash (lambda (k vs)
+              (mapc 'delete-file (cdr vs)))
+            table))
+  #-testing (ext:exit 0))
+
+(main)
+
diff --git a/macosx-port-reinstall b/macosx-port-reinstall
new file mode 100755
index 0000000..f709789
--- /dev/null
+++ b/macosx-port-reinstall
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -eu
+sudo port -qv installed  | cat > myports.txt
+sudo port echo requested | cut -d ' ' -f 1 > requested.txt
+sudo port -f uninstall installed
+sudo rm -rf /opt/local/var/macports/build/*
+curl --location --remote-name \
+    https://github.com/macports/macports-contrib/raw/master/restore_ports/restore_ports.tcl
+chmod +x restore_ports.tcl
+sudo ./restore_ports.tcl myports.txt
+sudo port unsetrequested installed
+xargs sudo port setrequested < requested.txt
ViewGit