shell-state.scm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (library (shell-state)
  2. (export get-shell-state
  3. update-shell-state*
  4. update-shell-state
  5. default-shell-state)
  6. (import (except (rnrs base) error map)
  7. (only (guile)
  8. lambda* λ
  9. getcwd)
  10. ;; (ice-9 exceptions)
  11. ;; lists
  12. (srfi srfi-1)
  13. (list-helpers)
  14. (alist-helpers))
  15. (define default-shell-state
  16. (let ([initial-pwd (getcwd)])
  17. `((last-exit-code . 0)
  18. (current-working-directory . ,initial-pwd)
  19. (directory-stack . ,(list initial-pwd)))))
  20. (define update-shell-state
  21. (λ (shell-state key val)
  22. "Data abstraction function for updating the shell state. Shell state
  23. is currently an alist, but maybe that changes in the future."
  24. (alist-set shell-state key val)))
  25. (define update-shell-state*
  26. (λ (shell-state keys vals)
  27. "Data abstraction function for updating the shell state. Shell state
  28. is currently an alist, but maybe that changes in the future."
  29. (let iter ([shell-state° shell-state]
  30. [keys° keys]
  31. [vals° vals])
  32. (cond
  33. [(null? keys°) shell-state°]
  34. [else
  35. (iter (alist-set shell-state° (car keys°) (car vals°))
  36. (cdr keys°)
  37. (cdr vals°))]))))
  38. (define get-shell-state
  39. (λ (shell-state key)
  40. "Data abstraction function for updating the shell state. Shell state
  41. is currently an alist, but maybe that changes in the future."
  42. (alist-refs shell-state (list key)))))