User Full Name
The following code parses the "/etc/passwd" file to
fetch the user's full-name:
;; ,open receiving srfi-2 scheme-with-scsh
(define user-gecos
(let ((read-passwd (field-reader (infix-splitter ":" 7))))
(lambda (username)
(call-with-input-file "/etc/passwd"
(lambda (port)
(let loop ()
(receive (record fields)
(read-passwd port)
(cond
((eof-object? record)
#f)
((string=? (list-ref fields 0) username)
(list-ref fields 4))
(else
(loop))))))))))
(define user-full-name
(let ((gecos-splitter (infix-splitter ",")))
(lambda (username)
(and-let* ((gecos (user-gecos username)))
(car (gecos-splitter gecos))))))
Sample usage:
(user-full-name (user-login-name))
UserFullName - raw wiki source |
code snippets archive
|