diff --git a/README.md b/README.md index 6477faf..a1d6822 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ For more information on SemVer, please visit [http://semver.org](http://semver.o - Enable errexit, nounset and pipefail at the top - More refined colors (thanks @arathai) - Add Changelog +- Add `__os` magic var - Add `__base` magic var - Enable long, GNU style options (thanks @zbeekman) diff --git a/main.sh b/main.sh index 7525e90..2bc2872 100755 --- a/main.sh +++ b/main.sh @@ -59,8 +59,10 @@ EOF __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" __file="${__dir}/$(basename "${BASH_SOURCE[0]}")" __base="$(basename ${__file} .sh)" - - +__os="Linux" +if [[ "${OSTYPE:-}" == "darwin"* ]]; then + __os="OSX" +fi ### Functions ##################################################################### @@ -221,17 +223,17 @@ fi ### Runtime ##################################################################### -if [[ "${OSTYPE:-}" == "darwin"* ]]; then - info "You are on OSX" -else - info "You are on Linux" -fi +info "__file: ${__file}" +info "__dir: ${__dir}" +info "__base: ${__base}" +info "__os: ${__os}" info "arg_f: ${arg_f}" info "arg_d: ${arg_d}" info "arg_v: ${arg_v}" info "arg_h: ${arg_h}" +# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software debug "Info useful to developers for debugging the application, not useful during operations." info "Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required." notice "Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required." diff --git a/test/fixture/debug.stdio b/test/fixture/debug.stdio index a192df4..20579d4 100644 --- a/test/fixture/debug.stdio +++ b/test/fixture/debug.stdio @@ -1,6 +1,9 @@ B3BP:STDIO_REPLACE_DATETIMES {datetime} UTC [ debug] cli arg arg_f = () -> {tmpdir}/x -{datetime} UTC [ info] You are on {os} +{datetime} UTC [ info] __file: {root}/main.sh +{datetime} UTC [ info] __dir: {root} +{datetime} UTC [ info] __base: main +{datetime} UTC [ info] __os: {os} {datetime} UTC [ info] arg_f: {tmpdir}/x {datetime} UTC [ info] arg_d: 0 {datetime} UTC [ info] arg_v: 0