12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- ;;#!/usr/bin/sbcl --script
- (defun split-string (string delimiter)
- (loop with len = (length string)
- with start = 0
- for end = (position delimiter string :start start)
- for substr = (if end
- (subseq string start end)
- (subseq string start))
- while end
- append (list substr)
- do (setf start (1+ end))
- until (= end len)))
- (defun list-files-in-directory (directory-path)
- (let* ((files (directory (merge-pathnames "*.*" (pathname directory-path))))
- (directory-pathname (pathname directory-path)))
- (mapcar #'(lambda (file)
- (merge-pathnames (pathname file) directory-pathname))
- files)))
- (defun bins-list ()
- (apply #'append
- (mapcar #'list-files-in-directory
- (loop for path in (split-string (sb-ext:posix-getenv "PATH") #\:)
- collect (format NIL "~a~c" path #\/)))))
- (defun random-bin (bins-list)
- (nth (random (length bins-list)) bins-list))
- (defun random-cmd (bins-list)
- (let ((number-of-pipes (random 4))
- (cmd-str ""))
- (if (> number-of-pipes 0)
- (progn
- (dotimes (i (+ 1 number-of-pipes))
- (setf cmd-str (concatenate 'string cmd-str (format NIL "~A | " (random-bin bins-list)))))
- (setf cmd-str (concatenate 'string (subseq cmd-str 0 (- (length cmd-str) 3)) (format NIL "~%"))))
- (setf cmd-str (concatenate 'string cmd-str (format NIL "~A~%" (random-bin bins-list)))))
- cmd-str))
-
- ;; (format T "~A" (random-cmd (bins-list)))
- (format T "~A" (random-bin (bins-list)))
|