* Newb me wrote bash script for TOC, for Org-mode in Github repos.
@ 2014-11-12 3:38 Brady Trainor
0 siblings, 0 replies; only message in thread
From: Brady Trainor @ 2014-11-12 3:38 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-11-12 3:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-12 3:38 Newb me wrote bash script for TOC, for Org-mode in Github repos Brady Trainor
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.