misc: cleanup

This commit is contained in:
Dylan Araps
2018-06-21 11:17:45 +10:00
parent f52d442128
commit 09a315df8d
2 changed files with 4 additions and 22 deletions

View File

@@ -17,24 +17,11 @@ src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
<img src="https://s3.amazonaws.com/titlepages.leanpub.com/bash/hero" width="40%" align="right"> <img src="https://s3.amazonaws.com/titlepages.leanpub.com/bash/hero" width="40%" align="right">
</a> </a>
The goal of this book is to document known and unknown methods of The goal of this book is to document known and unknown methods of doing various tasks using only built-in `bash` features. Using the snippets from this bible can help to remove unneeded dependencies from scripts and in most cases make them that little bit faster. I came across these tips and discovered a few while developing [neofetch](https://github.com/dylanaraps/neofetch), [pxltrm](https://github.com/dylanaraps/pxltrm) and some other smaller projects.
doing various tasks using only built-in `bash` features. Using the snippets
from this bible can help to remove unneeded dependencies from scripts
and in most cases make them that little bit faster. I came across these
tips and discovered a few while developing
[neofetch](https://github.com/dylanaraps/neofetch),
[pxltrm](https://github.com/dylanaraps/pxltrm) and some other smaller
projects.
The snippets below are linted using `shellcheck` and tests have been The snippets below are linted using `shellcheck` and tests have been written where applicable. Want to contribute? Have a read of the [CONTRIBUTING.md](https://github.com/dylanaraps/pure-bash-bible/blob/master/CONTRIBUTING.md). It outlines how the unit tests work and what is required when adding snippets to the bible.
written where applicable. Want to contribute? Have a read of
the
[CONTRIBUTING.md](https://github.com/dylanaraps/pure-bash-bible/blob/master/CONTRIBUTING.md).
It outlines how the unit tests work and what is required when adding
snippets to the bible.
See something that is incorrectly described, buggy or outright See something that is incorrectly described, buggy or outright wrong? Open an issue or send a pull request. If the bible is missing something, open an issue and a solution will be found.
wrong? Open an issue or send a pull request. If the bible is missing something, open an issue and a solution will be found.
<br> <br>
<p align="center"><b>This book is also available to purchase on leanpub. https://leanpub.com/bash</b></p> <p align="center"><b>This book is also available to purchase on leanpub. https://leanpub.com/bash</b></p>

View File

@@ -74,28 +74,24 @@ test_head() {
printf '%s\n%s\n\n\n' "hello" "world" > test_file printf '%s\n%s\n\n\n' "hello" "world" > test_file
result="$(head 2 test_file)" result="$(head 2 test_file)"
assert_equals "$result" $'hello\nworld' assert_equals "$result" $'hello\nworld'
rm test_file
} }
test_tail() { test_tail() {
printf '\n\n\n%s\n%s\n' "hello" "world" > test_file printf '\n\n\n%s\n%s\n' "hello" "world" > test_file
result="$(tail 2 test_file)" result="$(tail 2 test_file)"
assert_equals "$result" $'hello\nworld' assert_equals "$result" $'hello\nworld'
rm test_file
} }
test_lines() { test_lines() {
printf '\n\n\n\n\n\n\n\n' > test_file printf '\n\n\n\n\n\n\n\n' > test_file
result="$(lines test_file)" result="$(lines test_file)"
assert_equals "$result" "8" assert_equals "$result" "8"
rm test_file
} }
test_lines_loop() { test_lines_loop() {
printf '\n\n\n\n\n\n\n\n' > test_file printf '\n\n\n\n\n\n\n\n' > test_file
result="$(lines_loop test_file)" result="$(lines_loop test_file)"
assert_equals "$result" "8" assert_equals "$result" "8"
rm test_file
} }
test_count() { test_count() {
@@ -148,7 +144,6 @@ test_extract() {
printf '{\nhello, world\n}\n' > test_file printf '{\nhello, world\n}\n' > test_file
result="$(extract test_file "{" "}")" result="$(extract test_file "{" "}")"
assert_equals "$result" "hello, world" assert_equals "$result" "hello, world"
rm test_file
} }
test_split() { test_split() {
@@ -170,7 +165,7 @@ assert_equals() {
} }
main() { main() {
trap 'rm readme_code' EXIT trap 'rm readme_code test_file' EXIT
# Extract code blocks from the README. # Extract code blocks from the README.
while IFS=$'\n' read -r line; do while IFS=$'\n' read -r line; do