Skip to content

Commit

Permalink
Added build files to turn the bible into a book
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanaraps committed Jun 20, 2018
1 parent dbed16c commit e0aadbd
Show file tree
Hide file tree
Showing 23 changed files with 1,907 additions and 1 deletion.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ scripts and not full blown utilities.

<br>

<!-- CHAPTER START -->
# Table of Contents

<!-- vim-markdown-toc GFM -->
Expand Down Expand Up @@ -154,8 +155,11 @@ scripts and not full blown utilities.

<!-- vim-markdown-toc -->

<!-- CHAPTER END -->

<br>

<!-- CHAPTER START -->
# Strings

## Trim leading and trailing white-space from string
Expand Down Expand Up @@ -530,7 +534,9 @@ if [[ "$var" != *sub_string ]]; then
fi
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Arrays
## Reverse an array
Expand Down Expand Up @@ -659,6 +665,9 @@ cycle() {
}
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Loops
## Loop over a range of numbers
Expand Down Expand Up @@ -752,6 +761,9 @@ done
shopt -u globstar
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# File handling
**CAVEAT:** `bash` doesn't handle binary data properly in versions `< 4.4`.
Expand Down Expand Up @@ -939,7 +951,9 @@ $ extract ~/projects/pure-bash/README.md '```sh' '```'
# Output here...
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# File Paths
## Get the directory name of a file path
Expand Down Expand Up @@ -989,6 +1003,9 @@ $ basename ~/Pictures/Downloads/
Downloads
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Variables
## Assign and access a variable using a variable
Expand All @@ -1004,6 +1021,9 @@ var2="hello_${var1}"
printf '%s\n' "${!var2}"
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Escape Sequences
Contrary to popular belief, there's no issue in using raw escape sequences. Using `tput` just abstracts the same ANSI escape sequences. What's worse is that `tput` isn't actually portable, there are a number of different `tput` variants on different Operating Systems each with different commands (*try and run `tput setaf 3` on a FreeBSD system*). The easiest solution ends up being raw ANSI sequences.
Expand Down Expand Up @@ -1059,7 +1079,9 @@ Contrary to popular belief, there's no issue in using raw escape sequences. Usin
| `\e[2J\e[H` | Clear the screen and move cursor to `0,0`.
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Parameter Expansion
## Indirection
Expand Down Expand Up @@ -1126,6 +1148,9 @@ Contrary to popular belief, there's no issue in using raw escape sequences. Usin
| `${VAR?STRING}` | Display an error if unset.
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Brace Expansion
## Ranges
Expand Down Expand Up @@ -1166,6 +1191,9 @@ echo {apples,oranges,pears,grapes}
rm -rf ~/Downloads/{Movies,Music,ISOS}
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Arithmetic
## Simpler syntax to set variables
Expand Down Expand Up @@ -1195,6 +1223,9 @@ rm -rf ~/Downloads/{Movies,Music,ISOS}
((var=var2>var?var2:var))
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Traps
Traps allow you to execute code on various signals. In `pxltrm` I'm using traps to redraw the user interface on window resize. Another use case is cleaning up temporary files on script exit.
Expand Down Expand Up @@ -1236,6 +1267,9 @@ trap 'code_here' DEBUG
trap 'code_here' RETURN
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Performance
## Disable Unicode
Expand All @@ -1248,6 +1282,9 @@ LC_ALL=C
LANG=C
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Obsolete Syntax
## Shebang
Expand Down Expand Up @@ -1298,7 +1335,9 @@ function do_something() {
}
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Internal Variables
**NOTE**: This list does not include every internal variable (*You can
Expand Down Expand Up @@ -1397,6 +1436,9 @@ Each time `$RANDOM` is used, a different integer between `0` and `32767` is retu
"$RANDOM"
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Information about the terminal
## Get the terminal size in lines and columns (*from a script*)
Expand Down Expand Up @@ -1474,6 +1516,9 @@ $ get_cursor_pos
1 8
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Conversion
## Convert a hex color to RGB
Expand Down Expand Up @@ -1623,6 +1668,9 @@ esac
os="$_"
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Other
## Use `read` as an alternative to the `sleep` command
Expand Down Expand Up @@ -1814,6 +1862,9 @@ ls
command ls
```
<!-- CHAPTER END -->
<!-- CHAPTER START -->
# Afterword
Thanks for reading! If this bible helped you in any way and you'd like to give back, consider donating. Donations give me the time to make this the best resource possible. Can't donate? That's OK, star the repo and share it with your friends!
Expand Down
24 changes: 24 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Turn the single document bible into a book separated by chapters.

main() {
rm -rf manuscript
mkdir -p manuscript

# Split the README.md into chapters based on markers.
while IFS=$'\n' read -r line; do
[[ "$chap" ]] && chapter[$i]+="$line"$'\n'
[[ "$line" == "<!-- CHAPTER START -->" ]] && chap=1
[[ "$line" == "<!-- CHAPTER END -->" ]] && { chap=; ((i++)); }
done < README.md

# Write the chapters to separate files.
for i in "${!chapter[@]}"; do
: "${chapter[$i]/$'\n'*}"; : "${_/\# }"; : "${_,,}"
printf '%s\n' "${chapter[$i]}" > "manuscript/chapter${i}.txt"
printf '%s\n' "chapter${i}.txt" >> "manuscript/Book.txt"
done
}

main
19 changes: 19 additions & 0 deletions manuscript/Book.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
chapter0.txt
chapter1.txt
chapter2.txt
chapter3.txt
chapter4.txt
chapter5.txt
chapter6.txt
chapter7.txt
chapter8.txt
chapter9.txt
chapter10.txt
chapter11.txt
chapter12.txt
chapter13.txt
chapter14.txt
chapter15.txt
chapter16.txt
chapter17.txt
chapter18.txt
115 changes: 115 additions & 0 deletions manuscript/chapter0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Table of Contents

<!-- vim-markdown-toc GFM -->

* [Strings](#strings)
* [Trim leading and trailing white-space from string](#trim-leading-and-trailing-white-space-from-string)
* [Trim all white-space from string and truncate spaces](#trim-all-white-space-from-string-and-truncate-spaces)
* [Use regex on a string](#use-regex-on-a-string)
* [Split a string on a delimiter](#split-a-string-on-a-delimiter)
* [Change a string to lowercase](#change-a-string-to-lowercase)
* [Change a string to uppercase](#change-a-string-to-uppercase)
* [Trim quotes from a string](#trim-quotes-from-a-string)
* [Strip all instances of pattern from string](#strip-all-instances-of-pattern-from-string)
* [Strip first occurrence of pattern from string](#strip-first-occurrence-of-pattern-from-string)
* [Strip pattern from start of string](#strip-pattern-from-start-of-string)
* [Strip pattern from end of string](#strip-pattern-from-end-of-string)
* [Check if string contains a sub-string](#check-if-string-contains-a-sub-string)
* [Check if string starts with sub-string](#check-if-string-starts-with-sub-string)
* [Check if string ends with sub-string](#check-if-string-ends-with-sub-string)
* [Arrays](#arrays)
* [Reverse an array](#reverse-an-array)
* [Remove duplicate array elements](#remove-duplicate-array-elements)
* [Random array element](#random-array-element)
* [Cycle through an array](#cycle-through-an-array)
* [Toggle between two values](#toggle-between-two-values)
* [Loops](#loops)
* [Loop over a range of numbers](#loop-over-a-range-of-numbers)
* [Loop over a variable range of numbers](#loop-over-a-variable-range-of-numbers)
* [Loop over an array](#loop-over-an-array)
* [Loop over an array with an index](#loop-over-an-array-with-an-index)
* [Loop over the contents of a file](#loop-over-the-contents-of-a-file)
* [Loop over files and directories](#loop-over-files-and-directories)
* [File handling](#file-handling)
* [Read a file to a string](#read-a-file-to-a-string)
* [Read a file to an array (*by line*)](#read-a-file-to-an-array-by-line)
* [Get the first N lines of a file](#get-the-first-n-lines-of-a-file)
* [Get the last N lines of a file](#get-the-last-n-lines-of-a-file)
* [Get the number of lines in a file](#get-the-number-of-lines-in-a-file)
* [Count files or directories in directory](#count-files-or-directories-in-directory)
* [Create an empty file](#create-an-empty-file)
* [Extract lines between two markers](#extract-lines-between-two-markers)
* [File Paths](#file-paths)
* [Get the directory name of a file path](#get-the-directory-name-of-a-file-path)
* [Get the base-name of a file path](#get-the-base-name-of-a-file-path)
* [Variables](#variables)
* [Assign and access a variable using a variable](#assign-and-access-a-variable-using-a-variable)
* [Escape Sequences](#escape-sequences)
* [Text Colors](#text-colors)
* [Text Attributes](#text-attributes)
* [Cursor Movement](#cursor-movement)
* [Erasing Text](#erasing-text)
* [Parameter Expansion](#parameter-expansion)
* [Indirection](#indirection)
* [Replacement](#replacement)
* [Length](#length)
* [Expansion](#expansion)
* [Case Modification](#case-modification)
* [Default Value](#default-value)
* [Brace Expansion](#brace-expansion)
* [Ranges](#ranges)
* [String Lists](#string-lists)
* [Arithmetic](#arithmetic)
* [Simpler syntax to set variables](#simpler-syntax-to-set-variables)
* [Ternary tests](#ternary-tests)
* [Traps](#traps)
* [Do something on script exit](#do-something-on-script-exit)
* [Ignore terminal interrupt (CTRL+C, SIGINT)](#ignore-terminal-interrupt-ctrlc-sigint)
* [React to window resize.](#react-to-window-resize)
* [Do something before every command.](#do-something-before-every-command)
* [Do something when a shell function or a sourced file finishes executing](#do-something-when-a-shell-function-or-a-sourced-file-finishes-executing)
* [Performance](#performance)
* [Disable Unicode](#disable-unicode)
* [Obsolete Syntax](#obsolete-syntax)
* [Shebang](#shebang)
* [Command Substitution](#command-substitution)
* [Function Declaration](#function-declaration)
* [Internal Variables](#internal-variables)
* [Get the location to the `bash` binary](#get-the-location-to-the-bash-binary)
* [Get the version of the current running `bash` process](#get-the-version-of-the-current-running-bash-process)
* [Open the user's preferred text editor](#open-the-users-preferred-text-editor)
* [Get the name of the current function](#get-the-name-of-the-current-function)
* [Get the host-name of the system](#get-the-host-name-of-the-system)
* [Get the architecture of the Operating System](#get-the-architecture-of-the-operating-system)
* [Get the name of the Operating System / Kernel](#get-the-name-of-the-operating-system--kernel)
* [Get the current working directory](#get-the-current-working-directory)
* [Get the number of seconds the script has been running](#get-the-number-of-seconds-the-script-has-been-running)
* [Get a pseudorandom integer](#get-a-pseudorandom-integer)
* [Information about the terminal](#information-about-the-terminal)
* [Get the terminal size in lines and columns (*from a script*)](#get-the-terminal-size-in-lines-and-columns-from-a-script)
* [Get the terminal size in pixels](#get-the-terminal-size-in-pixels)
* [Get the current cursor position](#get-the-current-cursor-position)
* [Conversion](#conversion)
* [Convert a hex color to RGB](#convert-a-hex-color-to-rgb)
* [Convert an RGB color to hex](#convert-an-rgb-color-to-hex)
* [Code Golf](#code-golf)
* [Shorter `for` loop syntax](#shorter-for-loop-syntax)
* [Shorter infinite loops](#shorter-infinite-loops)
* [Shorter function declaration](#shorter-function-declaration)
* [Shorter `if` syntax](#shorter-if-syntax)
* [Simpler `case` statement to set variable](#simpler-case-statement-to-set-variable)
* [Other](#other)
* [Use `read` as an alternative to the `sleep` command](#use-read-as-an-alternative-to-the-sleep-command)
* [Check if a program is in the user's PATH](#check-if-a-program-is-in-the-users-path)
* [Get the current date using `strftime`](#get-the-current-date-using-strftime)
* [Generate a UUID V4](#generate-a-uuid-v4)
* [Progress bars](#progress-bars)
* [Get the list of functions from your script](#get-the-list-of-functions-from-your-script)
* [Bypass shell aliases](#bypass-shell-aliases)
* [Bypass shell functions](#bypass-shell-functions)
* [Afterword](#afterword)

<!-- vim-markdown-toc -->

<!-- CHAPTER END -->

Loading

0 comments on commit e0aadbd

Please sign in to comment.