pwd.scm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (library (commands pwd)
  2. (export pwd
  3. cwd
  4. path-working-directory
  5. current-working-directory)
  6. (import (except (rnrs base) error map)
  7. (only (guile)
  8. lambda* λ
  9. ;; formatting
  10. simple-format
  11. ;; ports
  12. with-output-to-port
  13. current-output-port
  14. ;; other
  15. getcwd
  16. ;; controll flow
  17. unless
  18. )
  19. (alias)
  20. (shell-state))
  21. (define pwd
  22. (lambda* (#:key
  23. ;; command interface
  24. (previous-result '())
  25. (shell-state default-shell-state)
  26. (silent #f))
  27. "Return the current working directory. pwd does not make use of the
  28. previous result, even if any is provided."
  29. (with-output-to-port (current-output-port)
  30. (λ ()
  31. (let ([cwd (getcwd)])
  32. ;; Write to output port.
  33. (unless silent
  34. (simple-format #t "~a\n" cwd))
  35. ;; Always return results and updated shell state.
  36. (values (list cwd)
  37. shell-state))))))
  38. (alias cwd pwd)
  39. (alias path-working-directory pwd)
  40. (alias current-working-directory pwd))