Skip to content

Instantly share code, notes, and snippets.

@equwal
Last active September 19, 2020 18:42
Show Gist options
  • Save equwal/67e60b203998154a205f7ca5dfa903c5 to your computer and use it in GitHub Desktop.
Save equwal/67e60b203998154a205f7ca5dfa903c5 to your computer and use it in GitHub Desktop.
Tags generator cron job
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#
(progn ;;init forms
(ros:ensure-asdf)
#+quicklisp(ql:quickload '() :silent t)
)
;;;; Generate etags for a list of files.
;;;; Add a command to cron like:
;;;; 0 0 * * * tag-gen ~/.config/tag-gen/tags.conf
;;;;
;;;; tags.conf needs to contain this kind of format:
;;;; (("<directory>" ("<ext>"...))
;;;; ...)
;;;;
;;;; For example:
;;;; (("/home/jose/.emacs.d" ("el"))
;;;; ("/home/jose/src/sf/sbcl/sbcl" ("lisp" "c")))
;;;;
;;;; Keep in mind that the home shorthand ~ might not git expanded properly!
;;;;
;;;; For debugging, call with a debug argument 0, 1, 2 where:
;;;; - 0 is silent
;;;; - 1 is for serious errors
;;;; - 2 is for everything
(defpackage :ros.script.tag-gen.3809526563
(:use :cl))
(in-package :ros.script.tag-gen.3809526563)
(defvar *log* nil)
(defvar *log-level* 0)
(defun add-to-log (str-log)
(when (and (/= 0 *log-level*)
(>= *log-level* (cdr str-log)))
(push (car str-log) *log*)))
(defun tag-gen (tags)
(labels ((extensions (dir exts)
(when exts
(add-to-log
(or (and (not (uiop:directory-exists-p dir))
(cons (format nil "The directory ~A doesn't exist" dir) 1))
(cons (uiop:run-program (format nil
"find ~A -type f -iname \"*.~A\""
dir
(car exts))
:ignore-error-status t
:output '(string :stripped t))
2)))
(extensions dir (cdr exts)))))
(when tags
(extensions (caar tags) (cadar tags))
(tag-gen (cdr tags)))))
(defun main (conf &optional (log-level *log-level*) &rest argv)
(declare (ignorable argv))
(let ((log-level (if (stringp log-level)
(parse-integer log-level)
log-level)))
(setf *log-level* log-level)
(with-open-file (s conf :direction :input)
(tag-gen (read s)))
(when *log*
(format t "~{~A~%~}" *log*))))
;;; vim: set ft=lisp lisp:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment