Browse Source

now results of shell commands are also converted into tables when appropriate

Eric Schulte 16 years ago
parent
commit
f27741e468
2 changed files with 39 additions and 1 deletions
  1. 19 1
      litorgy/litorgy-shell.el
  2. 20 0
      rorg.org

+ 19 - 1
litorgy/litorgy-shell.el

@@ -59,7 +59,25 @@ executed through litorgy."
             (error "currently no support for passing variables to shells"))
         (insert body)
         (shell-command-on-region (point-min) (point-max) cmd nil 'replace)
-        (buffer-string)))))
+        (litorgy-shell-to-elisp (buffer-string))))))
+
+(defun litorgy-shell-to-elisp (result)
+  (let ((tmp-file (make-temp-file "litorgy-shell")))
+    (with-temp-file tmp-file
+      (insert result))
+    (with-temp-buffer
+      (org-table-import tmp-file nil)
+      (delete-file tmp-file)
+      (setq result (mapcar (lambda (row)
+                             (mapcar #'litorgy-read row))
+                           (org-table-to-lisp)))
+      (if (null (cdr result)) ;; if result is trivial vector, then scalarize it
+          (if (consp (car result))
+              (if (null (cdr (car result)))
+                  (caar result)
+                result)
+            (car result))
+        result))))
 
 (provide 'litorgy-shell)
 ;;; litorgy-shell.el ends here

+ 20 - 0
rorg.org

@@ -126,6 +126,8 @@ evaluate them with =M-x eval-buffer=
 date
 #+end_src
 
+: Sun Apr  5 10:10:05 PDT 2009
+
 #+begin_src ruby
 puts Time.now
 #+end_src
@@ -281,6 +283,24 @@ tabel
 
 
 
+*** shell
+Now shell commands are converted to tables using =org-table-import=
+and if these tables are non-trivial (i.e. have multiple elements) then
+they are imported as org-mode tables...
+
+#+begin_src sh
+ls -l
+#+end_src
+
+| "total"      | 96 | ""         | ""         |    "" |   "" | "" | ""                |
+| "-rw-r--r--" |  1 | "eschulte" | "eschulte" |    57 | 2009 |  7 | "block"           |
+| "-rw-r--r--" |  1 | "eschulte" | "eschulte" | 35147 | 2009 |  7 | "COPYING"         |
+| "drwxr-xr-x" |  4 | "eschulte" | "eschulte" |  4096 | 2009 | 16 | "existing_tools"  |
+| "drwxr-xr-x" |  2 | "eschulte" | "eschulte" |  4096 | 2009 | 10 | "litorgy"         |
+| "-rw-r--r--" |  1 | "eschulte" | "eschulte" |   277 | 2009 | 15 | "README.markdown" |
+| "-rw-r--r--" |  1 | "eschulte" | "eschulte" | 41385 | 2009 | 10 | "rorg.org"        |
+
+
 
 ** silent evaluation