[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Newb me wrote bash script for TOC, for Org-mode in Github repos.
From: |
Brady Trainor |
Subject: |
[O] Newb me wrote bash script for TOC, for Org-mode in Github repos. |
Date: |
Tue, 11 Nov 2014 19:38:56 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] Newb me wrote bash script for TOC, for Org-mode in Github repos.,
Brady Trainor <=