spell.lisp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/sbcl --script
  2. (ql:quickload "uiop")
  3. (ql:quickload "split-sequence")
  4. ;; (defvar *path* (uiop:getenv "PATH"))
  5. ;; (defun file-is-executable-p (file-path)
  6. ;; (let ((oct-mode (mod (parse-integer (format NIL "~o" (sb-posix:stat-mode (sb-posix:stat file-path)))) 1000)))
  7. ;; (if (> oct-mode 711) T NIL)))
  8. (defun bins-list ()
  9. (apply #'append
  10. (mapcar #'uiop:directory-files
  11. (loop for path in (split-sequence:split-sequence #\: (uiop:getenv "PATH"))
  12. collect (format NIL "~a~c" path #\/)))))
  13. (defun random-bin (bins-list)
  14. (nth (random (length bins-list)) bins-list))
  15. (defun random-cmd (bins-list)
  16. (let ((number-of-pipes (random 4))
  17. (cmd-str ""))
  18. (if (> number-of-pipes 0)
  19. (progn
  20. (dotimes (i (+ 1 number-of-pipes))
  21. (setf cmd-str (concatenate 'string cmd-str (format NIL "~A | " (random-bin bins-list)))))
  22. (setf cmd-str (concatenate 'string (subseq cmd-str 0 (- (length cmd-str) 3)) (format NIL "~%"))))
  23. (setf cmd-str (concatenate 'string cmd-str (format NIL "~A~%" (random-bin bins-list)))))
  24. cmd-str))