From mboxrd@z Thu Jan 1 00:00:00 1970 From: Brady Trainor Subject: Newb me wrote bash script for TOC, for Org-mode in Github repos. Date: Tue, 11 Nov 2014 19:38:56 -0800 Message-ID: <87egt9hyun.fsf@uw.edu> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoOm2-0007HO-Eh for emacs-orgmode@gnu.org; Tue, 11 Nov 2014 22:39:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XoOlw-0002aK-WC for emacs-orgmode@gnu.org; Tue, 11 Nov 2014 22:39:14 -0500 Received: from plane.gmane.org ([80.91.229.3]:45562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoOlw-0002aB-QT for emacs-orgmode@gnu.org; Tue, 11 Nov 2014 22:39:08 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XoOlv-0002Ho-HF for emacs-orgmode@gnu.org; Wed, 12 Nov 2014 04:39:07 +0100 Received: from c-76-22-42-247.hsd1.wa.comcast.net ([76.22.42.247]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Nov 2014 04:39:07 +0100 Received: from algebrat by c-76-22-42-247.hsd1.wa.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Nov 2014 04:39:07 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org I think I have an okay bash script (below) for producing a TOC for notes I keep in Github in Org-mode format. It produce bulleted links like #+BEGIN_SRC org - [[./fileA.org][fileA.org]] - [[./dir][dir/]] - [[./dir/fileB.org][fileB.org]] #+END_SRC I run this script from a README.org file in my Github repo. My interaction with Github is a little frustrating, I think an extra blank line after =#+RESULTS:= prevents Github from omitting the entire list. Here is the script, it's more-or-less a very early program in my side project to learn programming. I think I have some inconsistencies in choosing to "" quote things. But it doesn't seem to be a problem. Hopefully I can learn Perl one day so I can do it in one line ;). I would have written it in Emacs Lisp since that is where I intended to use it, but I am still a little intimidated to learn this. Perhaps I will try to convert this to Emacs Lisp as an exercise at some point. Any comments are appreciated! (The choice of indentation as spaces is not the Org-mode convention (1,2,3... instead of 0,2,4...), but I choose simplicity in my scripts for now.) #+BEGIN_SRC emacs-lisp (setq org-babel-sh-command "bash") #+END_SRC #+BEGIN_SRC sh :results scalar raw replace #!/bin/bash echo PrevDepth=1 PrevDir="." find -regex '.*\.org' | while read file do Slashes="${file//[^\/]}" Depth="${#Slashes}" Dir=${file%/*} if [[ $Depth -eq $PrevDepth && "$Dir" != "$PrevDir" ]] || \ [[ $Depth -gt $PrevDepth ]] then for (( i=1 ; i <= Depth-1 ; i++ )); do echo -n ' '; done echo "- [[$Dir][${Dir##*/}/]]" fi for (( i=1; i<=Depth; i++ )); do echo -n ' '; done echo -n "- [[$file][${file##*/}]]" echo PrevDepth=$Depth PrevDir=$Dir done #+END_SRC -- Brady