-
Notifications
You must be signed in to change notification settings - Fork 386
Adding csplit support for GNU/Linux distros #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# -------------------- Utility Methods -------------------- | ||
# Check for binaries | ||
function checkEnvironment(){ | ||
type gcsplit >/dev/null 2>&1 || { echo "Install 'gcsplit' first (e.g. via 'brew install coreutils')." >&2 && exit 1 ; } | ||
type csplit >/dev/null 2>&1 || { echo "Install gcsplit' first (e.g. via 'brew install coreutils')." >&2 && exit 1 ; } | ||
type mdbook >/dev/null 2>&1 || { echo "Install 'mdbook' first (e.g. via 'cargo install mdbook')." >&2 && exit 1 ; } | ||
} | ||
|
||
|
@@ -18,15 +18,33 @@ function cleanupBeforeStarting(){ | |
|
||
# Splits the Readme.md file based on the header in markdown and creates chapters | ||
# Note: | ||
# Get gcsplit via homebrew on mac: brew install coreutils | ||
# Get csplit via homebrew on mac: brew install coreutils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is again wrong. On macOS you are using the gcsplit still on line 32 in this file. So saying csplit is being installed here is wrong. You might want to write this:
|
||
function splitIntoChapters(){ | ||
OS_NAME=$(uname | tr '[:upper:]' '[:lower:]') | ||
|
||
case $OS_NAME in | ||
linux*) | ||
OS_NAME='linux' | ||
csplit --prefix='Chapter_' --suffix-format='%d.md' --elide-empty-files README.md '/^## /' '{*}' -q | ||
;; | ||
darwin*) | ||
OS_NAME='osx' | ||
gcsplit --prefix='Chapter_' --suffix-format='%d.md' --elide-empty-files README.md '/^## /' '{*}' -q | ||
;; | ||
freebsd*) | ||
OS_NAME='freebsd' | ||
csplit --prefix='Chapter_' --suffix-format='%d.md' --elide-empty-files README.md '/^## /' '{*}' -q | ||
;; | ||
*) | ||
OS_NAME=notset | ||
;; | ||
esac | ||
Comment on lines
+23
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally donot prefer the switch statements in bash scripts. They are hard to read compared to simpler if-elif statements. You could have done something like below and executed the specific command: if [[ "$OSTYPE" == "linux-gnu" ]]; then
# ...
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "freebsd"* ]]; then
#FreeBSD
else
# Unknown.
fi |
||
} | ||
|
||
# Moves generated chapters into src directory | ||
function moveChaptersToSrcDir(){ | ||
for f in Chapter_*.md; do | ||
mv $f src/$f | ||
mv "$f" src/"$f" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
done | ||
} | ||
|
||
|
@@ -49,7 +67,7 @@ function createSummary(){ | |
# Note: | ||
# Install mdBook as per instructions in their repo https://github.com/rust-lang/mdBook | ||
function buildAndServeBookLocally(){ | ||
mdBook build && mdBook serve --open | ||
mdbook build && mdbook serve --open | ||
Comment on lines
-52
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was fixed in PR #105 |
||
} | ||
|
||
# -------------------- Steps to create the mdBook version -------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't remove the
gcsplit
line.Because on macOS gcsplit is used and it cannot be caught in Environment.
What you want to do is check for os type here using an if-else and then execute the check line for that os type.