summaryrefslogtreecommitdiff
path: root/com/simatime/shell.scm
blob: 7c6bb5cdd7cd1b086118b363842483248559a69f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(define-module (com simatime shell)
  #:use-module ((ice-9 popen) #:prefix popen/)
  #:use-module ((ice-9 rdelim) #:prefix rdelim/)
  #:use-module ((ice-9 ftw) #:prefix ftw/)
  #:export (exec
            stream
            pwd
            ls
            cd))

(define (exec cmd)
  (let* ((port (popen/open-input-pipe cmd))
         (ret (read port)))
    (popen/close-pipe port)
    ret))

(define (stream cmd)
  (let* ((port (popen/open-input-pipe cmd))
         (_ (setvbuf port 'none))
         (ret (rdelim/read-string port)))
    (flush-all-ports)
    (popen/close-pipe port)
    ret))

(define (pwd)
  (regexp-substitute/global
   #f "/home/ben" (getcwd) 'pre "~" 'post))

(define (ls)
  (ftw/scandir (getcwd)))

(define (cd path)
  (chdir path)
  (ls))