Skip to content

Commit e0aadbd

Browse files
committed
Added build files to turn the bible into a book
1 parent dbed16c commit e0aadbd

23 files changed

+1907
-1
lines changed

README.md

+51
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ scripts and not full blown utilities.
4141

4242
<br>
4343

44+
<!-- CHAPTER START -->
4445
# Table of Contents
4546

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

155156
<!-- vim-markdown-toc -->
156157

158+
<!-- CHAPTER END -->
159+
157160
<br>
158161

162+
<!-- CHAPTER START -->
159163
# Strings
160164

161165
## Trim leading and trailing white-space from string
@@ -530,7 +534,9 @@ if [[ "$var" != *sub_string ]]; then
530534
fi
531535
```
532536
537+
<!-- CHAPTER END -->
533538
539+
<!-- CHAPTER START -->
534540
# Arrays
535541
536542
## Reverse an array
@@ -659,6 +665,9 @@ cycle() {
659665
}
660666
```
661667
668+
<!-- CHAPTER END -->
669+
670+
<!-- CHAPTER START -->
662671
# Loops
663672
664673
## Loop over a range of numbers
@@ -752,6 +761,9 @@ done
752761
shopt -u globstar
753762
```
754763
764+
<!-- CHAPTER END -->
765+
766+
<!-- CHAPTER START -->
755767
# File handling
756768
757769
**CAVEAT:** `bash` doesn't handle binary data properly in versions `< 4.4`.
@@ -939,7 +951,9 @@ $ extract ~/projects/pure-bash/README.md '```sh' '```'
939951
# Output here...
940952
```
941953
954+
<!-- CHAPTER END -->
942955
956+
<!-- CHAPTER START -->
943957
# File Paths
944958
945959
## Get the directory name of a file path
@@ -989,6 +1003,9 @@ $ basename ~/Pictures/Downloads/
9891003
Downloads
9901004
```
9911005
1006+
<!-- CHAPTER END -->
1007+
1008+
<!-- CHAPTER START -->
9921009
# Variables
9931010
9941011
## Assign and access a variable using a variable
@@ -1004,6 +1021,9 @@ var2="hello_${var1}"
10041021
printf '%s\n' "${!var2}"
10051022
```
10061023
1024+
<!-- CHAPTER END -->
1025+
1026+
<!-- CHAPTER START -->
10071027
# Escape Sequences
10081028
10091029
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.
@@ -1059,7 +1079,9 @@ Contrary to popular belief, there's no issue in using raw escape sequences. Usin
10591079
| `\e[2J\e[H` | Clear the screen and move cursor to `0,0`.
10601080
10611081
1082+
<!-- CHAPTER END -->
10621083
1084+
<!-- CHAPTER START -->
10631085
# Parameter Expansion
10641086
10651087
## Indirection
@@ -1126,6 +1148,9 @@ Contrary to popular belief, there's no issue in using raw escape sequences. Usin
11261148
| `${VAR?STRING}` | Display an error if unset.
11271149
11281150
1151+
<!-- CHAPTER END -->
1152+
1153+
<!-- CHAPTER START -->
11291154
# Brace Expansion
11301155
11311156
## Ranges
@@ -1166,6 +1191,9 @@ echo {apples,oranges,pears,grapes}
11661191
rm -rf ~/Downloads/{Movies,Music,ISOS}
11671192
```
11681193
1194+
<!-- CHAPTER END -->
1195+
1196+
<!-- CHAPTER START -->
11691197
# Arithmetic
11701198
11711199
## Simpler syntax to set variables
@@ -1195,6 +1223,9 @@ rm -rf ~/Downloads/{Movies,Music,ISOS}
11951223
((var=var2>var?var2:var))
11961224
```
11971225
1226+
<!-- CHAPTER END -->
1227+
1228+
<!-- CHAPTER START -->
11981229
# Traps
11991230
12001231
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.
@@ -1236,6 +1267,9 @@ trap 'code_here' DEBUG
12361267
trap 'code_here' RETURN
12371268
```
12381269
1270+
<!-- CHAPTER END -->
1271+
1272+
<!-- CHAPTER START -->
12391273
# Performance
12401274
12411275
## Disable Unicode
@@ -1248,6 +1282,9 @@ LC_ALL=C
12481282
LANG=C
12491283
```
12501284
1285+
<!-- CHAPTER END -->
1286+
1287+
<!-- CHAPTER START -->
12511288
# Obsolete Syntax
12521289
12531290
## Shebang
@@ -1298,7 +1335,9 @@ function do_something() {
12981335
}
12991336
```
13001337
1338+
<!-- CHAPTER END -->
13011339
1340+
<!-- CHAPTER START -->
13021341
# Internal Variables
13031342
13041343
**NOTE**: This list does not include every internal variable (*You can
@@ -1397,6 +1436,9 @@ Each time `$RANDOM` is used, a different integer between `0` and `32767` is retu
13971436
"$RANDOM"
13981437
```
13991438
1439+
<!-- CHAPTER END -->
1440+
1441+
<!-- CHAPTER START -->
14001442
# Information about the terminal
14011443
14021444
## Get the terminal size in lines and columns (*from a script*)
@@ -1474,6 +1516,9 @@ $ get_cursor_pos
14741516
1 8
14751517
```
14761518
1519+
<!-- CHAPTER END -->
1520+
1521+
<!-- CHAPTER START -->
14771522
# Conversion
14781523
14791524
## Convert a hex color to RGB
@@ -1623,6 +1668,9 @@ esac
16231668
os="$_"
16241669
```
16251670
1671+
<!-- CHAPTER END -->
1672+
1673+
<!-- CHAPTER START -->
16261674
# Other
16271675
16281676
## Use `read` as an alternative to the `sleep` command
@@ -1814,6 +1862,9 @@ ls
18141862
command ls
18151863
```
18161864
1865+
<!-- CHAPTER END -->
1866+
1867+
<!-- CHAPTER START -->
18171868
# Afterword
18181869
18191870
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!

build.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Turn the single document bible into a book separated by chapters.
4+
5+
main() {
6+
rm -rf manuscript
7+
mkdir -p manuscript
8+
9+
# Split the README.md into chapters based on markers.
10+
while IFS=$'\n' read -r line; do
11+
[[ "$chap" ]] && chapter[$i]+="$line"$'\n'
12+
[[ "$line" == "<!-- CHAPTER START -->" ]] && chap=1
13+
[[ "$line" == "<!-- CHAPTER END -->" ]] && { chap=; ((i++)); }
14+
done < README.md
15+
16+
# Write the chapters to separate files.
17+
for i in "${!chapter[@]}"; do
18+
: "${chapter[$i]/$'\n'*}"; : "${_/\# }"; : "${_,,}"
19+
printf '%s\n' "${chapter[$i]}" > "manuscript/chapter${i}.txt"
20+
printf '%s\n' "chapter${i}.txt" >> "manuscript/Book.txt"
21+
done
22+
}
23+
24+
main

manuscript/Book.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
chapter0.txt
2+
chapter1.txt
3+
chapter2.txt
4+
chapter3.txt
5+
chapter4.txt
6+
chapter5.txt
7+
chapter6.txt
8+
chapter7.txt
9+
chapter8.txt
10+
chapter9.txt
11+
chapter10.txt
12+
chapter11.txt
13+
chapter12.txt
14+
chapter13.txt
15+
chapter14.txt
16+
chapter15.txt
17+
chapter16.txt
18+
chapter17.txt
19+
chapter18.txt

manuscript/chapter0.txt

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Table of Contents
2+
3+
<!-- vim-markdown-toc GFM -->
4+
5+
* [Strings](#strings)
6+
* [Trim leading and trailing white-space from string](#trim-leading-and-trailing-white-space-from-string)
7+
* [Trim all white-space from string and truncate spaces](#trim-all-white-space-from-string-and-truncate-spaces)
8+
* [Use regex on a string](#use-regex-on-a-string)
9+
* [Split a string on a delimiter](#split-a-string-on-a-delimiter)
10+
* [Change a string to lowercase](#change-a-string-to-lowercase)
11+
* [Change a string to uppercase](#change-a-string-to-uppercase)
12+
* [Trim quotes from a string](#trim-quotes-from-a-string)
13+
* [Strip all instances of pattern from string](#strip-all-instances-of-pattern-from-string)
14+
* [Strip first occurrence of pattern from string](#strip-first-occurrence-of-pattern-from-string)
15+
* [Strip pattern from start of string](#strip-pattern-from-start-of-string)
16+
* [Strip pattern from end of string](#strip-pattern-from-end-of-string)
17+
* [Check if string contains a sub-string](#check-if-string-contains-a-sub-string)
18+
* [Check if string starts with sub-string](#check-if-string-starts-with-sub-string)
19+
* [Check if string ends with sub-string](#check-if-string-ends-with-sub-string)
20+
* [Arrays](#arrays)
21+
* [Reverse an array](#reverse-an-array)
22+
* [Remove duplicate array elements](#remove-duplicate-array-elements)
23+
* [Random array element](#random-array-element)
24+
* [Cycle through an array](#cycle-through-an-array)
25+
* [Toggle between two values](#toggle-between-two-values)
26+
* [Loops](#loops)
27+
* [Loop over a range of numbers](#loop-over-a-range-of-numbers)
28+
* [Loop over a variable range of numbers](#loop-over-a-variable-range-of-numbers)
29+
* [Loop over an array](#loop-over-an-array)
30+
* [Loop over an array with an index](#loop-over-an-array-with-an-index)
31+
* [Loop over the contents of a file](#loop-over-the-contents-of-a-file)
32+
* [Loop over files and directories](#loop-over-files-and-directories)
33+
* [File handling](#file-handling)
34+
* [Read a file to a string](#read-a-file-to-a-string)
35+
* [Read a file to an array (*by line*)](#read-a-file-to-an-array-by-line)
36+
* [Get the first N lines of a file](#get-the-first-n-lines-of-a-file)
37+
* [Get the last N lines of a file](#get-the-last-n-lines-of-a-file)
38+
* [Get the number of lines in a file](#get-the-number-of-lines-in-a-file)
39+
* [Count files or directories in directory](#count-files-or-directories-in-directory)
40+
* [Create an empty file](#create-an-empty-file)
41+
* [Extract lines between two markers](#extract-lines-between-two-markers)
42+
* [File Paths](#file-paths)
43+
* [Get the directory name of a file path](#get-the-directory-name-of-a-file-path)
44+
* [Get the base-name of a file path](#get-the-base-name-of-a-file-path)
45+
* [Variables](#variables)
46+
* [Assign and access a variable using a variable](#assign-and-access-a-variable-using-a-variable)
47+
* [Escape Sequences](#escape-sequences)
48+
* [Text Colors](#text-colors)
49+
* [Text Attributes](#text-attributes)
50+
* [Cursor Movement](#cursor-movement)
51+
* [Erasing Text](#erasing-text)
52+
* [Parameter Expansion](#parameter-expansion)
53+
* [Indirection](#indirection)
54+
* [Replacement](#replacement)
55+
* [Length](#length)
56+
* [Expansion](#expansion)
57+
* [Case Modification](#case-modification)
58+
* [Default Value](#default-value)
59+
* [Brace Expansion](#brace-expansion)
60+
* [Ranges](#ranges)
61+
* [String Lists](#string-lists)
62+
* [Arithmetic](#arithmetic)
63+
* [Simpler syntax to set variables](#simpler-syntax-to-set-variables)
64+
* [Ternary tests](#ternary-tests)
65+
* [Traps](#traps)
66+
* [Do something on script exit](#do-something-on-script-exit)
67+
* [Ignore terminal interrupt (CTRL+C, SIGINT)](#ignore-terminal-interrupt-ctrlc-sigint)
68+
* [React to window resize.](#react-to-window-resize)
69+
* [Do something before every command.](#do-something-before-every-command)
70+
* [Do something when a shell function or a sourced file finishes executing](#do-something-when-a-shell-function-or-a-sourced-file-finishes-executing)
71+
* [Performance](#performance)
72+
* [Disable Unicode](#disable-unicode)
73+
* [Obsolete Syntax](#obsolete-syntax)
74+
* [Shebang](#shebang)
75+
* [Command Substitution](#command-substitution)
76+
* [Function Declaration](#function-declaration)
77+
* [Internal Variables](#internal-variables)
78+
* [Get the location to the `bash` binary](#get-the-location-to-the-bash-binary)
79+
* [Get the version of the current running `bash` process](#get-the-version-of-the-current-running-bash-process)
80+
* [Open the user's preferred text editor](#open-the-users-preferred-text-editor)
81+
* [Get the name of the current function](#get-the-name-of-the-current-function)
82+
* [Get the host-name of the system](#get-the-host-name-of-the-system)
83+
* [Get the architecture of the Operating System](#get-the-architecture-of-the-operating-system)
84+
* [Get the name of the Operating System / Kernel](#get-the-name-of-the-operating-system--kernel)
85+
* [Get the current working directory](#get-the-current-working-directory)
86+
* [Get the number of seconds the script has been running](#get-the-number-of-seconds-the-script-has-been-running)
87+
* [Get a pseudorandom integer](#get-a-pseudorandom-integer)
88+
* [Information about the terminal](#information-about-the-terminal)
89+
* [Get the terminal size in lines and columns (*from a script*)](#get-the-terminal-size-in-lines-and-columns-from-a-script)
90+
* [Get the terminal size in pixels](#get-the-terminal-size-in-pixels)
91+
* [Get the current cursor position](#get-the-current-cursor-position)
92+
* [Conversion](#conversion)
93+
* [Convert a hex color to RGB](#convert-a-hex-color-to-rgb)
94+
* [Convert an RGB color to hex](#convert-an-rgb-color-to-hex)
95+
* [Code Golf](#code-golf)
96+
* [Shorter `for` loop syntax](#shorter-for-loop-syntax)
97+
* [Shorter infinite loops](#shorter-infinite-loops)
98+
* [Shorter function declaration](#shorter-function-declaration)
99+
* [Shorter `if` syntax](#shorter-if-syntax)
100+
* [Simpler `case` statement to set variable](#simpler-case-statement-to-set-variable)
101+
* [Other](#other)
102+
* [Use `read` as an alternative to the `sleep` command](#use-read-as-an-alternative-to-the-sleep-command)
103+
* [Check if a program is in the user's PATH](#check-if-a-program-is-in-the-users-path)
104+
* [Get the current date using `strftime`](#get-the-current-date-using-strftime)
105+
* [Generate a UUID V4](#generate-a-uuid-v4)
106+
* [Progress bars](#progress-bars)
107+
* [Get the list of functions from your script](#get-the-list-of-functions-from-your-script)
108+
* [Bypass shell aliases](#bypass-shell-aliases)
109+
* [Bypass shell functions](#bypass-shell-functions)
110+
* [Afterword](#afterword)
111+
112+
<!-- vim-markdown-toc -->
113+
114+
<!-- CHAPTER END -->
115+

0 commit comments

Comments
 (0)