Skip to content

Instantly share code, notes, and snippets.

@jasonrobot
Created May 8, 2018 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrobot/fecc0da6f29fa6f5136376876a14dca0 to your computer and use it in GitHub Desktop.
Save jasonrobot/fecc0da6f29fa6f5136376876a14dca0 to your computer and use it in GitHub Desktop.
Simple command line invoked timer. I plan to add some way of notifying.
#!/usr/bin/sbcl --script
;;; Documentation:
;;; Commentary:
;;; Code:
(defun timer-tick ()
"Waits for 1 second"
(sleep 1))
(defun update-display (time-left)
"Write TIME-LEFT to stdout, replacing whatever was on the last line previously."
(format t "~C~D" #\return time-left)
(finish-output))
(defun run-timer (time)
"Runs a countdown timer for TIME seconds."
(loop
for current-time
from time
downto 1
do (progn
(update-display current-time)
(timer-tick)))
(format t "~CDone!" #\return))
(defun my-command-line ()
"Reads command line args."
(or
#+CLISP *args*
#+SBCL *posix-argv*
#+LISPWORKS system:*line-arguments-list*
#+CMU extensions:*command-line-words*
nil))
;;; Script:
(let ((time (parse-integer (elt (my-command-line) 1))))
(run-timer time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment