-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcommands.lisp
48 lines (39 loc) · 1.61 KB
/
commands.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;; Slowly migrating my zsh aliases here...
(uiop:define-package :fare-scripts/commands
(:use :cl :uiop :fare-utils
:inferior-shell :cl-scripting :cl-launch/dispatch)
(:export #:fare-dir #:src-root #:common-lisp-src #:cl-root
#:getuid #:stow-root #:restow
#:fare-scripts-symlinks #:help))
(in-package :fare-scripts/commands)
(exporting-definitions
(defun fare-dir () (getenv-absolute-directory "FARE"))
(defun src-root () (subpathname (fare-dir) "src/"))
(defun common-lisp-src () (subpathname (src-root) "common-lisp/"))
(defun cl-root () (subpathname (fare-dir) "cl/"))
(defun getuid ()
#+sbcl (sb-posix:getuid)
#-sbcl (error "no getuid")) ;; use iolib?
(defun stow-root ()
(if (zerop (getuid))
#p"/usr/local/stow/"
(subpathname (fare-dir) "local/stow/")))
(defun restow ()
(with-current-directory ((stow-root))
(run `(stow "-R" ,@(mapcar (lambda (x) (car (last (pathname-directory x)))) (subdirectories "."))))
(run '(symlinks -rd "..")))
(success))
(defun fare-scripts-symlinks ()
(let ((binarch (resolve-absolute-location `(,(getenv "BINDIR") ,(getenv "BINARCH")) :ensure-directory t)))
(with-current-directory (binarch)
(dolist (i (cl-launch/dispatch:all-entry-names))
(unless (file-exists-p i)
(format t "linking file ~A~%" i)
(run `("ln" "-s" "fare-scripts" ,i))))))
(success))
(defun help ()
(format! t "~A available commands: ~{~A~^ ~}~%" (get-name) (all-entry-names))
(success))
);exporting-definitions
;; Not all our exported symbols are worth exposing to the shell command-line.
(register-commands :fare-scripts/commands)