diff --git a/FUNCTIONS.adoc b/FUNCTIONS.adoc index 2febc6b..7743a0d 100644 --- a/FUNCTIONS.adoc +++ b/FUNCTIONS.adoc @@ -847,12 +847,12 @@ bashmatic.functions-from () local pattern="${1}" [[ -n ${pattern} ]] && shift [[ -z ${pattern} ]] && pattern="[a-z]*.sh" - cd "${BASHMATIC_LIBDIR}" > /dev/null || return 1 + cd "${BASHMATIC_HOME}/lib" > /dev/null || return 1 export SCREEN_WIDTH=$(screen-width) if [[ ! ${pattern} =~ * && ! ${pattern} =~ .sh$ ]]; then pattern="${pattern}.sh" fi - ${GrepCommand} '^[_a-zA-Z0-9]+.*\(\)' ${pattern} | sedx 's/^lib\/.*\.sh://g' | sedx 's/^function //g' | sedx 's/\(\) *\{.*$//g' | tr -d '()' | sedx '/^ *$/d' | ${GrepCommand} '^_' -v | sort | uniq | columnize "$@" + ${GrepCommand} '^[_a-zA-Z0-9]+.*\(\)' ${pattern} | sedx 's/^(lib\/)?.*\.sh://g' | sedx 's/^function //g' | sedx 's/\(\) *\{.*$//g' | tr -d '()' | sedx '/^ *$/d' | ${GrepCommand} '^(_|\.)' -v | sort | uniq | columnize "$@" cd - > /dev/null || return 1 } @@ -4403,20 +4403,6 @@ net.local-subnet () === Module `openssl` -==== `.openssl.certs.print-generated` - -[source,bash] ----- -.openssl.certs.print-generated () -{ - local file="$1" - h.blue "Would you like to view the generated certificate?" - run.ui.ask "Press any key to view, or Ctrl-C to abort." - openssl req -text -in "${file}" -noout -verify -} - ----- - ==== `openssl.certs.generate-csr` [source,bash] @@ -9289,128 +9275,6 @@ url.valid-status () === Module `usage` -==== `.usage-cache-file` - -[source,bash] ----- -.usage-cache-file () -{ - local script_name="${BASH_SOURCE[-1]}" - local script_dir="$(dirname ${script_name})" - local script_base="$(basename ${script_name})" - local script_usage_cache="${script_dir}/.${script_base}" - printf "%s" "${script_usage_cache}" -} - ----- - -==== `.usage.begin` - -[source,bash] ----- -.usage.begin () -{ - .usage.setup "$@" - .output.box-top "${__color_bdr}" -} - ----- - -==== `.usage.box` - -[source,bash] ----- -.usage.box () -{ - local command - local title - if [[ "${1}" =~ "©" ]]; then - command="${1/ © */}" - title="${1/* © /}" - else - command="$1" - title= - fi - shift - .usage.begin - .usage.command "${command}" - [[ -n ${title} ]] && .usage.title "${title}" - [[ -n "$*" ]] && .usage.flags "$@" -} - ----- - -==== `.usage.flags` - -[source,bash] ----- -.usage.flags () -{ - local -a flags=("$@") - local line="" - local n=0 - local l=0 - local l_flags=0 - local l_desc=0 - for arg in "$@" - do - if (($(($n % 2)) == 0)); then - l=${#arg} - [[ $l -gt ${l_flags} ]] && l_flags=$l - else - [[ $l -gt ${l_desc} ]] && l_desc=$l - fi - n=$((n + 1)) - done - if [[ ${l_flags} -eq 0 ]]; then - l_flags="${LibUsage__NoFlagsIndent}" - else - if [[ ${l_flags} -lt ${LibUsage__MinFlagLen} ]]; then - l_flags=${LibUsage__MinFlagLen} - fi - fi - local n=0 - .output.boxed-text "${__color_bdr}" "${__color_headers}" "$(.usage.hdr flags)" - for arg in "$@" - do - if (($(($n % 2)) == 0)); then - local left_color=${__color_flag} - local left_prefix=" " - if [[ ${arg:0:1} == "├" ]]; then - .output.box-separator "${__color_bdr}" - arg=${arg:1} - left_color="${__color_sub_headers}" - left_prefix="" - fi - line=$(printf "${left_prefix}${left_color}%-${l_flags}s" "${arg}") - else - line=$(printf "%s${__color_fg} %s\n" "${line}" "${arg}") - .output.boxed-text "${__color_bdr}" "${__color_cmd}" "${line}" - fi - n=$((n + 1)) - done - printf "${__color_bdr}" - .output.box-bottom -} - ----- - -==== `.usage.setup` - -[source,bash] ----- -.usage.setup () -{ - export __color_fg=${1:-${txtylw}} - export __color_bdr=${2:-${txtblu}} - export __color_cmd=${3:-${txtgrn}} - export __color_flag=${4:-${txtpur}} - export __color_headers=${5:-${bldred}} - export __color_sub_headers=${5:-${bldcyn}} -} - ----- - ==== `help-command` [source,bash] diff --git a/USAGE.adoc b/USAGE.adoc index 49d2b66..bc9476d 100644 --- a/USAGE.adoc +++ b/USAGE.adoc @@ -38,8 +38,8 @@ Miscellaneous utilities. == array.has-element() - Returns "true" if the first argument is a member of the array - passed as the second argument: +Returns "true" if the first argument is a member of the array + passed as the second argument: === Example @@ -53,12 +53,12 @@ Miscellaneous utilities. == array.includes() - Similar to array.has-elements, but does not print anything, just - returns 0 if includes, 1 if not. +Similar to array.has-elements, but does not print anything, just + returns 0 if includes, 1 if not. == array.join() - Joins a given array with a custom character +Joins a given array with a custom character === Example @@ -95,9 +95,9 @@ Sorts the array numerically and prints it to STDOUT == array.min() - Returns a minimum integer from an array. - Non-numeric elements are ignored and skipped over. - Negative numbers are supported, but non-integers are not. +Returns a minimum integer from an array. + Non-numeric elements are ignored and skipped over. + Negative numbers are supported, but non-integers are not. === Example @@ -110,9 +110,9 @@ Sorts the array numerically and prints it to STDOUT == array.max() - Returns a maximum integer from an array. - Non-numeric elements are ignored and skipped over. - Negative numbers are supported, but non-integers are not. +Returns a maximum integer from an array. + Non-numeric elements are ignored and skipped over. + Negative numbers are supported, but non-integers are not. === Example diff --git a/USAGE.md b/USAGE.md new file mode 100644 index 0000000..ed6f73d --- /dev/null +++ b/USAGE.md @@ -0,0 +1,751 @@ + +## Module **array** + +* [array.has-element()](#arrayhas-element) +* [array.includes()](#arrayincludes) +* [array.join()](#arrayjoin) +* [array.sort()](#arraysort) +* [array.sort-numeric()](#arraysort-numeric) +* [array.min()](#arraymin) +* [array.max()](#arraymax) +* [array.uniq()](#arrayuniq) + + +### array.has-element() + + + Returns "true" if the first argument is a member of the array + passed as the second argument: + +#### Example + +```bash + $ declare -a array=("a string" test2000 moo) + if [[ $(array.has-element "a string" "${array[@]}") == "true" ]]; then + ... + fi +``` + +### array.includes() + + + Similar to array.has-elements, but does not print anything, just + returns 0 if includes, 1 if not. + +### array.join() + + + Joins a given array with a custom character + +#### Example + +```bash + $ declare -a array=(one two three) + $ array.join "," "${array[@]}" + one,two,three +``` + +### array.sort() + +Sorts the array alphanumerically and prints it to STDOUT + +#### Example + +```bash + declare -a unsorted=(hello begin again again) + local sorted="$(array.sort "${unsorted[@]}")" +``` + +### array.sort-numeric() + +Sorts the array numerically and prints it to STDOUT + +#### Example + +```bash + declare -a unsorted=(1 2 34 45 6) + local sorted="$(array.sort-numeric "${unsorted[@]}")" +``` + +### array.min() + + + Returns a minimum integer from an array. + Non-numeric elements are ignored and skipped over. + Negative numbers are supported, but non-integers are not. + +#### Example + +```bash + $ declare -a array=(10 20 30 -5 5) + $ array.min "," "${array[@]}" + -5 +``` + +### array.max() + + + Returns a maximum integer from an array. + Non-numeric elements are ignored and skipped over. + Negative numbers are supported, but non-integers are not. + +#### Example + +```bash + $ declare -a array=(10 20 30 -5 5) + $ array.min "," "${array[@]}" + 30 +``` + +### array.uniq() + +Sorts and uniqs the array and prints it to STDOUT + +#### Example + +```bash + declare -a unsorted=(hello hello hello goodbye) + local uniqued="$(array.sort-numeric "${unsorted[@]}")" +``` + + +## Module **db** + +* [db.config.parse()](#dbconfigparse) +* [db.psql.connect()](#dbpsqlconnect) +* [db.psql.connect.just-data()](#dbpsqlconnectjust-data) +* [db.psql.db-settings()](#dbpsqldb-settings) +* [db.psql.connect.settings-table()](#dbpsqlconnectsettings-table) +* [db.psql.connect.settings-ini()](#dbpsqlconnectsettings-ini) + + +### db.config.parse() + +Returns a space-separated values of db host, db name, username and password + +#### Example + +```bash + db.config.set-file ~/.db/database.yml + db.config.parse development + #=> hostname dbname dbuser dbpass + declare -a params=($(db.config.parse development)) + echo ${params[0]} # host +``` + +### db.psql.connect() + +Connect to one of the databases named in the YAML file, and + optionally pass additional arguments to psql. + Informational messages are sent to STDERR. + +#### Example + +```bash + db.psql.connect production + db.psql.connect production -c 'show all' +``` + +### db.psql.connect.just-data() + +Similar to the db.psql.connect, but outputs + just the raw data with no headers. + +#### Example + +```bash + db.psql.connect.just-data production -c 'select datname from pg_database;' +``` + +### db.psql.db-settings() + +Print out PostgreSQL settings for a connection specified by args + +#### Example + +```bash + db.psql.db-settings -h localhost -U postgres appdb +``` + +### db.psql.connect.settings-table() + +Print out PostgreSQL settings for a named connection + +#### Arguments + +* # @arg1 dbname database entry name in ~/.db/database.yml + +#### Example + +```bash + db.psql.connect.settings-table primary +``` + +### db.psql.connect.settings-ini() + +Print out PostgreSQL settings for a named connection using TOML/ini + format. + +#### Arguments + +* # @arg1 dbname database entry name in ~/.db/database.yml + +#### Example + +```bash + db.psql.connect.settings-ini primary > primary.ini +``` + + +## Module **git** +# Bashmatic Utilities and aliases for Git revision control system. + +Lots of useful utilities and helpers. + +* [git.open()](#gitopen) + + +### git.open() + +Reads the remote of a repo by name provided as + an argument (or defaults to "origin") and opens it in the browser. + +#### Example + +```bash +git clone git@github.com:kigster/bashmatic.git +cd bashmatic +source init.sh +git.open +git.open origin # same thing +``` + +#### Arguments + +* **$1** (optional): name of the remote to open, defaults to "orogin" + + +## Module **is** +# is.sh + + +* [__is.validation.error()](#isvalidationerror) +* [is-validations()](#is-validations) +* [__is.validation.ignore-error()](#isvalidationignore-error) +* [__is.validation.report-error()](#isvalidationreport-error) +* [whenever()](#whenever) +* [unless()](#unless) + + +### __is.validation.error() + + Invoke a validation on the value, and process + the invalid case using a customizable error handler. + +#### Arguments + +* # @arg1 func Validation function name to invoke +* # @arg2 var Value under the test +* # @arg4 error_func Error function to call when validation fails + +#### Exit codes + +* **0**: if validation passes + +### is-validations() + +Returns the list of validation functions available + +### __is.validation.ignore-error() + +Private function that ignores errors + +### __is.validation.report-error() + +Private function that ignores errors + +### whenever() + +a convenient DSL for validating things + +#### Example + +```bash + whenever /var/log/postgresql.log is.an-empty-file && { + touch /var/log/postgresql.log + } +``` + +### unless() + +a convenient DSL for validating things + +#### Example + +```bash + unless /var/log/postgresql.log is.an-non-empty-file && { + touch /var/log/postgresql.log + } +``` + + +## Module **openssl** + +* [.openssl.certs.print-generated()](#opensslcertsprint-generated) + + +### .openssl.certs.print-generated() + +Generate a CSR for NGINX domain + + +## Module **osx** +# osx.sh + +OSX Specific Helpers and Utilities + +* [osx.app.is-installed()](#osxappis-installed) + + +### osx.app.is-installed() + +@description + Checks if a given parameter matches any of the installed applications + under /Applications and ~/Applications + + By the default prints the matched application. Pass `-q` as a second + argument to disable output. + +#### Example + +```bash + ❯ osx.app.is-installed safari + Safari.app + ❯ osx.app.is-installed safari -q && echo installed + installed + ❯ osx.app.is-installed microsoft -c + 6 +``` + +#### Arguments + +* **$1** (a): string value to match (case insentively) for an app name +* $2.. additional arguments to the last invocation of `grep` + +#### Exit codes + +* **0**: if match was found +* **1**: if not + + +## Module **output** + +* [section()](#section) +* [is-dbg()](#is-dbg) +* [dbg()](#dbg) + + +### section() + +Prints a "arrow-like" line using powerline characters + +#### Arguments + +* # @arg1 Width (optional) — only intepretered as width if the first argument is a number. +* # @args Text to print + +### is-dbg() + +Checks if we have debug mode enabled + +### dbg() + +Local debugging helper, activate it with DEBUG=1 + + +## Module **path** + +* [path.add()](#pathadd) +* [path.append()](#pathappend) +* [PATH_add()](#pathadd) + + +### path.add() + +Adds valid directories to those in the PATH and prints + to the output. DOES NOT MODIFY $PATH + +### path.append() + +Appends valid directories to those in the PATH, and + exports the new value of the PATH + +### PATH_add() + +This function exists within direnv, but since we + are sourcing in .envrc we need to have this defined + to avoid errors. + + +## Module **pdf** +# Bashmatic Utilities for PDF file handling + +Install and uses GhostScript to manipulate PDFs. + +* [pdf.combine()](#pdfcombine) + + +### pdf.combine() + +Combine multiple PDFs into a single one using ghostscript. + +#### Example + +```bash +pdf.combine ~/merged.pdf 'my-book-chapter*' +``` + +#### Arguments + +* **$1** (pathname): to the merged file +* **...** (the): rest of the PDF files to combine + + +## Module **array** + +* [array.has-element()](#arrayhas-element) +* [array.includes()](#arrayincludes) +* [array.join()](#arrayjoin) +* [array.sort()](#arraysort) +* [array.sort-numeric()](#arraysort-numeric) +* [array.min()](#arraymin) +* [array.max()](#arraymax) +* [array.uniq()](#arrayuniq) + + +### array.has-element() + + + Returns "true" if the first argument is a member of the array + passed as the second argument: + +#### Example + +```bash + $ declare -a array=("a string" test2000 moo) + if [[ $(array.has-element "a string" "${array[@]}") == "true" ]]; then + ... + fi +``` + +### array.includes() + + + Similar to array.has-elements, but does not print anything, just + returns 0 if includes, 1 if not. + +### array.join() + + + Joins a given array with a custom character + +#### Example + +```bash + $ declare -a array=(one two three) + $ array.join "," "${array[@]}" + one,two,three +``` + +### array.sort() + +Sorts the array alphanumerically and prints it to STDOUT + +#### Example + +```bash + declare -a unsorted=(hello begin again again) + local sorted="$(array.sort "${unsorted[@]}")" +``` + +### array.sort-numeric() + +Sorts the array numerically and prints it to STDOUT + +#### Example + +```bash + declare -a unsorted=(1 2 34 45 6) + local sorted="$(array.sort-numeric "${unsorted[@]}")" +``` + +### array.min() + + + Returns a minimum integer from an array. + Non-numeric elements are ignored and skipped over. + Negative numbers are supported, but non-integers are not. + +#### Example + +```bash + $ declare -a array=(10 20 30 -5 5) + $ array.min "," "${array[@]}" + -5 +``` + +### array.max() + + + Returns a maximum integer from an array. + Non-numeric elements are ignored and skipped over. + Negative numbers are supported, but non-integers are not. + +#### Example + +```bash + $ declare -a array=(10 20 30 -5 5) + $ array.min "," "${array[@]}" + 30 +``` + +### array.uniq() + +Sorts and uniqs the array and prints it to STDOUT + +#### Example + +```bash + declare -a unsorted=(hello hello hello goodbye) + local uniqued="$(array.sort-numeric "${unsorted[@]}")" +``` + + +## Module **db** + +* [db.config.parse()](#dbconfigparse) +* [db.psql.connect()](#dbpsqlconnect) +* [db.psql.connect.just-data()](#dbpsqlconnectjust-data) +* [db.psql.db-settings()](#dbpsqldb-settings) +* [db.psql.connect.settings-table()](#dbpsqlconnectsettings-table) +* [db.psql.connect.settings-ini()](#dbpsqlconnectsettings-ini) + + +### db.config.parse() + +Returns a space-separated values of db host, db name, username and password + +#### Example + +```bash + db.config.set-file ~/.db/database.yml + db.config.parse development + #=> hostname dbname dbuser dbpass + declare -a params=($(db.config.parse development)) + echo ${params[0]} # host +``` + +### db.psql.connect() + +Connect to one of the databases named in the YAML file, and + optionally pass additional arguments to psql. + Informational messages are sent to STDERR. + +#### Example + +```bash + db.psql.connect production + db.psql.connect production -c 'show all' +``` + +### db.psql.connect.just-data() + +Similar to the db.psql.connect, but outputs + just the raw data with no headers. + +#### Example + +```bash + db.psql.connect.just-data production -c 'select datname from pg_database;' +``` + +### db.psql.db-settings() + +Print out PostgreSQL settings for a connection specified by args + +#### Example + +```bash + db.psql.db-settings -h localhost -U postgres appdb +``` + +### db.psql.connect.settings-table() + +Print out PostgreSQL settings for a named connection + +#### Arguments + +* # @arg1 dbname database entry name in ~/.db/database.yml + +#### Example + +```bash + db.psql.connect.settings-table primary +``` + +### db.psql.connect.settings-ini() + +Print out PostgreSQL settings for a named connection using TOML/ini + format. + +#### Arguments + +* # @arg1 dbname database entry name in ~/.db/database.yml + +#### Example + +```bash + db.psql.connect.settings-ini primary > primary.ini +``` + + +## Module **git** +# Bashmatic Utilities and aliases for Git revision control system. + +Lots of useful utilities and helpers. + +* [git.open()](#gitopen) + + +### git.open() + +Reads the remote of a repo by name provided as + an argument (or defaults to "origin") and opens it in the browser. + +#### Example + +```bash +git clone git@github.com:kigster/bashmatic.git +cd bashmatic +source init.sh +git.open +git.open origin # same thing +``` + +#### Arguments + +* **$1** (optional): name of the remote to open, defaults to "orogin" + + +## Module **is** +# is.sh + + +* [__is.validation.error()](#isvalidationerror) +* [is-validations()](#is-validations) +* [__is.validation.ignore-error()](#isvalidationignore-error) +* [__is.validation.report-error()](#isvalidationreport-error) +* [whenever()](#whenever) +* [unless()](#unless) + + +### __is.validation.error() + + Invoke a validation on the value, and process + the invalid case using a customizable error handler. + +#### Arguments + +* # @arg1 func Validation function name to invoke +* # @arg2 var Value under the test +* # @arg4 error_func Error function to call when validation fails + +#### Exit codes + +* **0**: if validation passes + +### is-validations() + +Returns the list of validation functions available + +### __is.validation.ignore-error() + +Private function that ignores errors + +### __is.validation.report-error() + +Private function that ignores errors + +### whenever() + +a convenient DSL for validating things + +#### Example + +```bash + whenever /var/log/postgresql.log is.an-empty-file && { + touch /var/log/postgresql.log + } +``` + +### unless() + +a convenient DSL for validating things + +#### Example + +```bash + unless /var/log/postgresql.log is.an-non-empty-file && { + touch /var/log/postgresql.log + } +``` + + +## Module **openssl** + +* [.openssl.certs.print-generated()](#opensslcertsprint-generated) + + +### .openssl.certs.print-generated() + +Generate a CSR for NGINX domain + + +## Module **osx** +# osx.sh + +OSX Specific Helpers and Utilities + +* [osx.app.is-installed()](#osxappis-installed) + + +### osx.app.is-installed() + +@description + Checks if a given parameter matches any of the installed applications + under /Applications and ~/Applications + + By the default prints the matched application. Pass `-q` as a second + argument to disable output. + +#### Example + +```bash + ❯ osx.app.is-installed safari + Safari.app + ❯ osx.app.is-installed safari -q && echo installed + installed + ❯ osx.app.is-installed microsoft -c + 6 +``` + +#### Arguments + +* **$1** (a): string value to match (case insentively) for an app name +* $2.. additional arguments to the last invocation of `grep` + +#### Exit codes + +* **0**: if match was found +* **1**: if not + diff --git a/bin/bashmatic b/bin/bashmatic index b0fd7f8..75f2ae2 100755 --- a/bin/bashmatic +++ b/bin/bashmatic @@ -16,26 +16,9 @@ # # syntax. -[[ -z ${BASHMATIC_HOME} ]] && { - if [[ -d ${HOME}/.bashmatic ]]; then - export BASHMATIC_HOME=${HOME}/.bashmatic - elif [[ $0 =~ bin/bashmatic$ ]]; then - export BASHMATIC_HOME="$( cd $(dirname $(dirname $0)); pwd -P)" - else - for source in "${BASH_SOURCE[@]}"; do - if [[ ${source} =~ bin/bashmatic ]]; then - export BASHMATIC_HOME="$( cd $(dirname $(dirname ${source})); pwd -P)" - fi - done - fi - - [[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="${HOME}/.bashmatic" - echo "BASHMATIC_HOME=${BASHMATIC_HOME}" >&2 -} - -( [[ -d ${BASHMATIC_HOME} ]] || bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v -H ${BASHMATIC_HOME}" ) - -source "${BASHMATIC_HOME}/init.sh" 2>/dev/null +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" if is.a-function "$1"; then eval "$@" diff --git a/bin/db b/bin/db index 78fce33..a8399ee 100755 --- a/bin/db +++ b/bin/db @@ -1,8 +1,8 @@ #!/usr/bin/env bash # vim: ft=sh - -[[ -d ${BASHMATIC_HOME} ]] || bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v" -source "${BASHMATIC_HOME}/init.sh" 1>/dev/null +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" action="$1" shift diff --git a/bin/dbtop b/bin/dbtop index 89c71e7..99e99b5 100755 --- a/bin/dbtop +++ b/bin/dbtop @@ -1,8 +1,9 @@ #!/usr/bin/env bash # vim: ft=sh -[[ -d ${BASHMATIC_HOME} ]] || bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v" -source "${BASHMATIC_HOME}/init.sh" 1>/dev/null +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" db.top "$@" diff --git a/bin/dev-setup b/bin/dev-setup index 8e0ebac..2b6fbbc 100755 --- a/bin/dev-setup +++ b/bin/dev-setup @@ -2,10 +2,8 @@ # vim: ft=bash # shellcheck disable=2046 -export BASHMATIC_HOME="$(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P)" - -set +x -source "${BASHMATIC_HOME}/init.sh" 1>/dev/null +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" export DEFAULT_RUBY_VERSION="2.7.1" export DEFAULT_POSTGRESQL_VERSION="11" diff --git a/bin/dock b/bin/dock index 47ffc61..7af7054 100755 --- a/bin/dock +++ b/bin/dock @@ -2,7 +2,9 @@ # vim: ft=bash set -e -source "${BASHMATIC_HOME}/init.sh" 1>/dev/null +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" export tag="bashmatic:latest" diff --git a/bin/docs b/bin/docs index 7bc1bba..295c42d 100755 --- a/bin/docs +++ b/bin/docs @@ -5,8 +5,8 @@ # Distributed under the MIT LICENSE. # shellcheck disable=2046 -export BASHMATIC_HOME="$(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P)" -source "${BASHMATIC_INIT}" +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" function setup() { [[ -n $(command -V gawk) ]] || brew.install.package gawk diff --git a/bin/downloader b/bin/downloader index f05351a..ffe621a 100755 --- a/bin/downloader +++ b/bin/downloader @@ -6,6 +6,8 @@ # This script can extract image URLs from a remote HTML document(s) and # downloads them all to a local folder. +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" [[ -d "${BASHMATIC_HOME}" ]] || bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v" 1>/dev/null 2>/dev/null # vim: ft=bash diff --git a/bin/install-grc b/bin/install-grc index 34ace88..dceccc3 100755 --- a/bin/install-grc +++ b/bin/install-grc @@ -8,8 +8,9 @@ # © 2020 Konstantin Gredeskoul, distributed as part of Bashmatic Framework. # -[[ -d ${BASHMATIC_HOME} ]] || bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v" -source "${BASHMATIC_HOME}/init.sh" 1>/dev/null +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" run.set-all abort-on-error diff --git a/bin/mysql-ramdisk b/bin/mysql-ramdisk index f6617ea..af2b8c9 100755 --- a/bin/mysql-ramdisk +++ b/bin/mysql-ramdisk @@ -2,10 +2,8 @@ # vim: ft=bash # shellcheck disable=2046 -export BASHMATIC_HOME="$(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P)" - -set +x -source "${BASHMATIC_HOME}/init.sh" 1>/dev/null +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" run.set-all abort-on-error output.set-max-width 100 diff --git a/bin/pdf-reduce b/bin/pdf-reduce index 3037f53..8894ddf 100755 --- a/bin/pdf-reduce +++ b/bin/pdf-reduce @@ -6,11 +6,9 @@ # This script can extract image URLs from a remote HTML document(s) and # downloads them all to a local folder. -# shellcheck disable=SC1134,SC2155 -[[ -d "${BASHMATIC_HOME}" ]] || bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v" 1>/dev/null 2>&1 - -# shellcheck source=/dev/null -. "${BASHMATIC_HOME}/init.sh" >/dev/null 2>&1 +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" # This project is derived from the +shrinkpdf+ open source project: # diff --git a/bin/puma-ctl b/bin/puma-ctl index f8f5240..fd0164b 100755 --- a/bin/puma-ctl +++ b/bin/puma-ctl @@ -7,15 +7,10 @@ set +e -export BashMatic="${BASHMATIC_HOME}" - -[[ -s ${BashMatic}/init.sh ]] || { - rm -rf "${BashMatic}" 2>/dev/null - bash -c "$(curl -fsSL https://bashmatic.re1.re); bashmatic-install -v" -} - -source ${BASHMATIC_HOME}/init.sh - +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" +\ # https://blog.phusion.nl/2017/10/13/why-ruby-app-servers-break-on-macos-high-sierra-and-what-can-be-done-about-it/ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES export RAILS_ENV="${RAILS_ENV:-"development"}" diff --git a/bin/readme-adoc2pdf b/bin/readme-adoc2pdf index c0bf837..d391a56 100755 --- a/bin/readme-adoc2pdf +++ b/bin/readme-adoc2pdf @@ -1,7 +1,10 @@ #!/usr/bin/env bash # vim: ft=bash -source ${BASHMATIC_HOME}/init.sh +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" + main() { local file="${1:-"README.adoc"}" diff --git a/bin/regen-index-docs b/bin/regen-index-docs index f3b7500..a29c4db 100755 --- a/bin/regen-index-docs +++ b/bin/regen-index-docs @@ -2,8 +2,7 @@ # vim: ft=sh # shellcheck disable=2046 -export BASHMATIC_HOME="${BASHMATIC_HOME:-"$(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P)"}" - +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" source "${BASHMATIC_HOME}/init.sh" list.modules() { diff --git a/bin/specs b/bin/specs index 8047f58..3126bce 100755 --- a/bin/specs +++ b/bin/specs @@ -6,22 +6,10 @@ # IMPORTANT: Overrride this variable if your tests are located in a different folder, eg 'specs' # shellcheck disable=2046 -export BASHMATIC_HOME="$(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P)" +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" export BASHMATIC_TEST_DIR="${BASHMATIC_TEST_DIR:-"test"}" -for loc in "${BASHMATIC_HOME}/init.sh" "${BASHMATIC_HOME}/init.sh" "${PWD}/init.sh"; do - if [[ -s "${loc}" ]]; then - export BASHMATIC_HOME="$(dirname "${loc}")" - break - fi -done - -[[ -s "${BASHMATIC_HOME}/init.sh" ]] || { - echo "Unable to find Bashmatic installation in ${BASHMATIC_HOME}..." - exit 1 -} - -source "${BASHMATIC_HOME}/init.sh" test-group() { #box.black-on-blue "$@" diff --git a/bin/upgrade-shell b/bin/upgrade-shell index 091f89f..40aba72 100755 --- a/bin/upgrade-shell +++ b/bin/upgrade-shell @@ -18,6 +18,10 @@ return } +# shellcheck disable=2046 +[[ -z ${BASHMATIC_HOME} ]] && export BASHMATIC_HOME="$(dirname $(cd $(dirname "${BASH_SOURCE[0]:-${(%):-%x}}") || exit 1; pwd -P))" +source "${BASHMATIC_HOME}/init.sh" + export SHELL_BASH_OSX="/bin/bash" export SHELL_BASH_BREW="/usr/local/bin/bash" diff --git a/lib/array.sh b/lib/array.sh index 05809b4..b8f4f64 100644 --- a/lib/array.sh +++ b/lib/array.sh @@ -8,8 +8,8 @@ #——————————————————————————————————————————————————————————————————————————————— # @description -# Returns "true" if the first argument is a member of the array -# passed as the second argument: +# Returns "true" if the first argument is a member of the array +# passed as the second argument: # # @example # $ declare -a array=("a string" test2000 moo) @@ -34,8 +34,8 @@ array.has-element() { } # @description -# Similar to array.has-elements, but does not print anything, just -# returns 0 if includes, 1 if not. +# Similar to array.has-elements, but does not print anything, just +# returns 0 if includes, 1 if not. array.includes() { local search="$1"; shift [[ "$*" =~ ${search} ]] || return 1 @@ -78,7 +78,7 @@ array.includes-or-exit() { } # @description -# Joins a given array with a custom character +# Joins a given array with a custom character # # @example # $ declare -a array=(one two three) @@ -137,9 +137,9 @@ array.sort-numeric() { } # @description -# Returns a minimum integer from an array. -# Non-numeric elements are ignored and skipped over. -# Negative numbers are supported, but non-integers are not. +# Returns a minimum integer from an array. +# Non-numeric elements are ignored and skipped over. +# Negative numbers are supported, but non-integers are not. # # @example # $ declare -a array=(10 20 30 -5 5) @@ -155,9 +155,9 @@ array.min() { } # @description -# Returns a maximum integer from an array. -# Non-numeric elements are ignored and skipped over. -# Negative numbers are supported, but non-integers are not. +# Returns a maximum integer from an array. +# Non-numeric elements are ignored and skipped over. +# Negative numbers are supported, but non-integers are not. # # @example # $ declare -a array=(10 20 30 -5 5)