Skip to content

Instantly share code, notes, and snippets.

@GrafBlutwurst
Last active November 18, 2020 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrafBlutwurst/d9d1a320d84ca47d4b8756cd53b72276 to your computer and use it in GitHub Desktop.
Save GrafBlutwurst/d9d1a320d84ca47d4b8756cd53b72276 to your computer and use it in GitHub Desktop.

Shell scripts

This is the literate programming notebook for /shell/scripts. Because this is a ton of arcane bash I thought it’d be nice if it was thoroughly documented. For the readers sake, do not assume that they read previous entries. They might only be interested in one particular script. If you find yourself documenting something over and over put a reference.

Construct the shebang-line. If you want to tangle this file from within emacs, put your cursor on the codeblock and press `C-c C-c` “` (defconst shebang-line (concat “#!” (locate-file “bash” exec-path exec-suffixes 1))) “`

Workspace Tooling & Utility scripts

Tangling Org Files

So the whole point of these longwinded documents is that they should serve as the primary way of adding and chaning shell scripts. This is to avoid stale documentation and alleviate the pain that is bash. One of the most common tasks in literate programming is “tangling” taking a document like this where documentation and code are interwoven and generating output files that are runnable. A side effect of this is if you want to rip out literate programming, just tangle everything, export the documentation to e.g. md and yeet the original org-files.

The literate programing implementation i went for is called org-babel and is part of emacs org-mode. I understand that I’ll probably be forever the only emacs user ever in Rivero so i created a helper script that you never have to interact with emacs yourself. Also note that all tangled files are actually commited to git. So you porbably wont even ever touch this file unless you are updating the org-files.

All we do is checking if the passed argument to ~org-tanvgle “shell.org”~ exists and if so, call emacs in batch mode to tangle the file. “` org_file=$1 if [ -f $org_file ]; then echo “Tangling ORG File: $org_file” emacs -Q \ –batch \ –eval “(require ‘org)” \ –eval ‘(defconst shebang-line (concat “#!” (locate-file “bash” exec-path exec-suffixes 1)))’ \ –eval “(org-babel-tangle-file "$org_file")” 2> /dev/null fi “`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment