I'm new to Linux and Bash, and I want to make a text-based book readable from the terminal. The idea is to run something like tractatus 1.222 to see a section, or tractatus --tree to see the whole book. Where should I start?
How should I build a terminal app for a tree-structured book?
Answers
Start with the book data, not the command interface. Give each section an identifier such as 1, 1.2 or 1.222, and store its text in a consistent format. Then write a small script that looks up the exact identifier passed as the first argument.
Once that works, add --tree to print the sections in order. Decide whether it should show the full text or just identifiers and headings, since those are rather different views. Also handle a missing or unknown identifier with a short usage message.
Reply to this answer
Have a look at GNU Info pages too. They support linked sections and terminal navigation, so they might give you useful ideas or even save you from building a reader from scratch. Check whether that navigation fits what you want before committing to it.
slightly.untagged_5:
What are Info pages?
n47+ratchet_502:
They're documentation pages you can read in a terminal with the info command. They can be organized into linked sections, which Info calls nodes.
Reply to this answer
Bash is fine for a small prototype, especially if learning it is part of the goal. Keep the text separate from the script so editing the book doesn't mean editing code. If parsing the format gets awkward, a language with stronger text and data handling may be easier later.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Brindleby.7:
Watch out for section ordering. Sorting identifiers as ordinary numbers can produce a different order from sorting their dot-separated parts.