;;; Filesystem Outline Generator

(defun fo-tree-output-to-org ()
  "Converts the depth representation of the `tree' command to stars.
Point in the current buffer should be at the start of the output."
    (replace-regexp "    ?" "*"))
    (replace-regexp "\\(|\\|`?--\\)" ""))
  (replace-regexp "^" "*")
  (delete-char 1))

(defun filesystem-outline (root)
  "Generates an Org Mode file from the output of `tree ROOT'."
  (interactive "DRoot directory: ")
  (let* ((root (file-name-as-directory root))
         (name (file-name-nondirectory (substring root 0 -1)))
         (buffer (generate-new-buffer (format "*Outline of %s*" name))))
    (set-buffer buffer)
    (insert "-*- mode: org -*-")
    (insert "\n")
    (shell-command (format "tree %s -a --noreport --dirsfirst" root) t)
    (goto-char (point-min))
      (next-line 1)
      (let ((kill-whole-line t))
    (switch-to-buffer buffer)