From: Brady Trainor <algebrat@uw.edu>
To: emacs-orgmode@gnu.org
Subject: Newb me wrote bash script for TOC, for Org-mode in Github repos.
Date: Tue, 11 Nov 2014 19:38:56 -0800 [thread overview]
Message-ID: <87egt9hyun.fsf@uw.edu> (raw)
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
reply other threads:[~2014-11-12 3:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87egt9hyun.fsf@uw.edu \
--to=algebrat@uw.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.