diff --git a/importers/network.scm b/importers/network.scm index 8881b5e..7b4f5c4 100644 --- a/importers/network.scm +++ b/importers/network.scm @@ -3,3 +3,38 @@ ;; - [ ] is connected using wifi or ethernet ;; - [ ] if wifi, the netkwork name ;; - [ ] network usage (speed) + +(add-to-load-path "..") + +(use-modules (ice-9 popen) + (ice-9 textual-ports) + (org helpers) + (org format)) + +(define (run-command command-string) + (let* ((port + (open-input-pipe command-string)) + (str (get-string-all port))) + (close-pipe port) + (string-trim-both str))) + +(define active-connections-command + (string-join '("nmcli -t" "con" "show" "--active"))) + +;; TODO: alist is better, fix org-format +(define (make-connection-list conn) + (let ((params '("NAME" "UUID" "TYPE" "DEVICE"))) + (map (lambda (x y) `(,x ,y)) + params conn))) + +(define (split-on-colone str) (string-split str #\:)) + +(define (active-connections) + (map (lambda (c) (make-connection-list c)) + (map split-on-colon + (string-split + (run-command active-connections-command) + #\nl)))) + +(map org-properties (active-connections)) +