dot_guile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;; -*- mode: Scheme; fill-column: 78; -*-
  2. (define-macro (try function)
  3. `(catch 'quit (lambda () ,function) (const #f)))
  4. (define (system->string command)
  5. (let* ((port ((@@ (ice-9 popen) open-pipe) command OPEN_READ))
  6. (output ((@@ (ice-9 rdelim) read-string) port)))
  7. ((@@ (ice-9 popen) close-pipe) port)
  8. output))
  9. (define (system->string* . args)
  10. (let* ((port (apply (@@ (ice-9 popen) open-pipe*) OPEN_READ args))
  11. (output ((@@ (ice-9 rdelim) read-string) port)))
  12. ((@@ (ice-9 popen) close-pipe) port)
  13. output))
  14. (define (expand-file-name path)
  15. (system->string (string-join (list "readlink" "-nf" path))))
  16. (cond ((false-if-exception (resolve-interface '(ice-9 readline)))
  17. =>
  18. (lambda (module)
  19. ;; Enable completion and input history at the REPL.
  20. ((module-ref module 'activate-readline))))
  21. (else
  22. (display "Consider installing the 'guile-readline' package for
  23. convenient interactive line editing and input history.\n\n")))
  24. (unless (getenv "INSIDE_EMACS")
  25. (cond ((false-if-exception (resolve-interface '(ice-9 colorized)))
  26. =>
  27. (lambda (module)
  28. ;; Enable completion and input history at the REPL.
  29. ((module-ref module 'activate-colorized))))
  30. (else
  31. (display "Consider installing the 'guile-colorized' package
  32. for a colorful Guile experience.\n\n"))))
  33. (use-modules (srfi srfi-1))
  34. (when (string-prefix? "guix" (last (string-split (getcwd) #\/)))
  35. (use-modules (guix)
  36. (guix build utils)
  37. (guix store)
  38. (system repl command)
  39. (ice-9 pretty-print)))
  40. (define c
  41. (if (string-prefix? "guix" (last (string-split (getcwd) #\/)))
  42. (open-connection)
  43. #f))
  44. (when (string-prefix? "guix" (last (string-split (getcwd) #\/)))
  45. (define-meta-command ((xref guix) repl arg)
  46. "xref SYMBOL
  47. Find symbol in GUILE_PATH"
  48. (pk (symbol-location arg)))
  49. (define-meta-command ((gnu guix) repl arg)
  50. "gnu MODULE
  51. Invoke (use-modules (gnu packages MODULE))"
  52. (cond ((false-if-exception (resolve-interface `(gnu packages ,arg)))
  53. =>
  54. (lambda (module)
  55. ;; Enable completion and input history at the REPL.
  56. (module-use! (current-module) module)))
  57. (else
  58. (display "Missing module.\n\n")))))
  59. (define (ssh-node host)
  60. (use-modules (ssh session)
  61. (ssh auth)
  62. (ssh dist)
  63. (ssh dist node))
  64. (define session
  65. (make-session #:host host))
  66. (connect! session)
  67. (userauth-public-key/auto! session)
  68. (make-node session))