diff options
| author | mryouse | 2022-05-26 03:25:04 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-26 03:25:04 +0000 |
| commit | 856989c4dc74803678464399a21024e7b5d24985 (patch) | |
| tree | 756f0f3a8d992ef2ceb5e2e8559cf252afb51716 /neighborcat | |
| parent | 9ce7dd3bc706d2a3c9599c184001e1482e10e218 (diff) | |
more neighborcat implementation
Diffstat (limited to 'neighborcat')
| -rw-r--r-- | neighborcat/neighborcat.neb | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/neighborcat/neighborcat.neb b/neighborcat/neighborcat.neb index b134311..c5fa1a8 100644 --- a/neighborcat/neighborcat.neb +++ b/neighborcat/neighborcat.neb @@ -11,6 +11,7 @@ '---''(_/--' `-'\_) ") +; get a user from their /home/*/* path (func user-from-path (inp) (first (rest (rest (split inp "/"))))) @@ -18,27 +19,41 @@ (func get-porches () (map user-from-path (glob (concat HOME "*" PORCH)))) +; add " * " to the beginning of the string (func concat-star (inp) (concat " * " inp)) +; pretty-print all porches (func print-porches () + (print "Neighborhood porches") (map print (map concat-star (get-porches)))) +; get all eats available on a given porch (func get-eats (porch) (glob (concat HOME porch BOWL "*"))) +; get all eats on all porches (func get-porches-with-eats () (map get-eats (get-porches))) -(func locate () +; find the cat +(func locate-cat () (glob (concat HOME "*" PORCH NAME))) +(func locate () + (def porch (locate-cat)) + (if (empty? porch) + (print (concat "hmm, " PRONOUN "must have wandered off. maybe you should leave some food?")) + (print (concat "last I saw " NAME ", " PRONOUN " was on " (user-from-path (first porch)) "'s porch")))) + (func get-random-eats () + ; expected format ((porch1/eat1 porch1/eat2) (porch2/eat1)...) (safe-first (shuf (safe-first (shuf (get-porches-with-eats)))))) +; prevent a panic on (first ()) (func safe-first (inp) (if (empty? inp) () @@ -46,21 +61,59 @@ (func wander () (print (concat "off " PRONOUN " goes!")) - (def current-location (locate)) + (def current-location (locate-cat)) (if (not (empty? current-location)) (print (concat "need to unlink: " (first current-location)))) - ; this should probably return and not exit? + ; if there's no eats, exit (def target-eats (get-random-eats)) (if (and (list? target-eats) (empty? target-eat)) (exit)) - (def target-porch (user-from-path target-eats)) + ; eat the food + ;(unlink target-eats) + + ; go to the porch + (def target-eats-stem (last (split target-eats "/"))) + ;(def target-porch (user-from-path target-eats)) + (def target-porch "mryouse") + (with-write (concat HOME target-porch PORCH NAME) + (write CAT _file_) + (write (concat "thank you for the " target-eats-stem "!" (newline)) _file_))) + +(func init () + ; create the new porch and bowl + ;(def new_porch (concat HOME USER PORCH)) + (def new_porch "newporch") + (if (not (exists? new_porch)) + ($ (concat "mkdir -m 777 " new_porch))) + ;(def new_bowl (concat HOME USER BOWL)) + (def new_bowl "newporch/newbowl") + (if (not (exists? new_bowl)) + ($ (concat "mkdir -m 777 " new_bowl))) + + ; get rid of the old stuff, if applicable + ; TODO + + (print "You're all set up!") + + ) + +(func help () + (print "neighborcat -- a neighborhood cat") + (print " -> 'init' : initialize your porch") + (print " -> 'locate' : locate the neighborcat") + (print " -> 'feed <food>' : locate the neighborcat") + (print " -> 'wander' : send the cat a-wandering")) - ) ; end of wander +(func main (args) + (branch + ((empty? args) (print-porches)) + ((eq? "init" (first args)) (init)) + ((eq? "help" (first args)) (help)) + ((eq? "wander" (first args)) (wander)) + ((eq? "locate" (first args)) (locate)) + ((eq? "feed" (first args)) (feed (rest args))) + (#true + (print (concat "unknown argument: " (first args)))))) -; options -;(print-porches) -;(print (->string (get-porches-with-eats))) -;(print USER) -;(print (->string (locate))) -(wander) +(main (rest (argv))) |
