Commit Graph

80 Commits

Author SHA1 Message Date
Germain Masse
12ea4dd75f
Enable color in screen or tmux 2017-08-13 21:08:59 +02:00
Izaak Beekman
cb29b2f984
Restore @mstreuhofer's changes that I clobbered 2017-02-10 19:00:00 -05:00
Izaak Beekman
0d1f488365
Fix shellchk and show usage for new magic var
Update acceptance tests
2017-02-10 18:58:35 -05:00
Manuel Streuhofer
d879ae1fe0 fixup example.sh like 2.3.0 main.sh
__i_am_main_script logic fixed for example.sh
added double-sourced test
2017-02-10 20:40:38 +01:00
Kevin van Zonneveld
382217eebf Update version 2017-02-10 15:32:48 +01:00
Izaak Beekman
7cf9ea708d Issue 44 issue 21 issue 47 (#85)
* Fix shifting over `--`: don't throw errexit

 Fixes #21

* Add error trapping (including Ctrl-C) info to FAQ

 Closes #47

* Add backtracing to help localize errors

 - Fixes #44
 - Backtracing is turned on when the debugging `-d` flag is passed,
   otherwise backtracing function defined but signal trap not set.
 - Update main-help fixture due to moving trap

* Untabify main.sh

 Might be a controversial move, but I loath tabs...

* Add checks for tab chars and trailing whitespace

 - Update poor-man's style enforcement script to check for these
   violations
 - Better document style guidlines in README with small tweaks

* Add a magic variable to indicate if being source

 if `__i_am_main_script=1 #true` then `main.sh` called directly
 Fixes #45
2017-02-10 15:03:07 +01:00
Manuel Streuhofer
d383e8c098 prepared changelog for release 2.2.0 (#82)
moved entries in changelog from `unreleased` to 2.1.0 (even
though technically it's too late for that since that version was already
released).

added new section for 2.2.0 and added some points on what changed.

bumped version to 2.2.0 in main.sh, example.sh and package.json

Closes #74
2016-12-21 09:29:02 +01:00
Manuel Streuhofer
cf85af8c15 brace all variables, used [[ instead of [ (#76)
Closes #33
2016-12-14 09:54:25 +01:00
Manuel Streuhofer
9350e0574c added automatic usage validation for required args
If the description of an option contains the single word sentence
'Required.' it is understood as a required argument and automatic
validation will make sure that it is set or end the script by calling
help.

Alternatively, if the argument within the __usage string is {arg}
instead of [arg] it is understood as a required argument and automatic
validation will make sure that it is set or end the script by calling
help (even if 'Required.' is not in the description).

Closes #22
2016-12-09 00:54:52 +01:00
Manuel Streuhofer
1e69fd5e21 removed all usage of eval, proper usage of unset
replaced all `eval` with `printf -v` for security reasons.

the behaviour of unset without -v/-f is actually undefined so make the
intent clear.
2016-12-06 18:06:25 +01:00
Izaak Beekman
68323978d4 Merge pull request #70 from mstreuhofer/color
Fix auto-color-off code

 Thanks to @mstreuhofer for another great contribution 🎊 🙇
2016-12-05 12:37:28 -05:00
Manuel Streuhofer
b8bdaf371a get rid of awk, sed & egrep usage 2016-12-03 18:52:40 +01:00
Manuel Streuhofer
290c65d4b9 fix auto-color-off code
turn off colors if NO_COLOR is "true" or TERM is not "xterm*" or STDERR
is not connected to a terminal, but ignore TERM and STDERR if NO_COLOR
is set to "false" explicitly.

Fixes #69
2016-12-03 18:52:10 +01:00
Manuel Streuhofer
9b739b4cf0 Fix some code caught by shellcheck (#68) 2016-12-01 14:40:56 +01:00
Manuel Streuhofer
539443b3ca Allow for multiline opt description in __usage. Fixes #7 2016-11-11 20:13:01 +01:00
Manuel Streuhofer
dfd799b4e5 b3bp sourced mode (#61)
If main.sh is being sourced instead of being executed it respects the
variables __usage and __helptext being defined beforehand. Its behaviour
will depend on the sourcing script. If __usage is defined but empty no
argument parsing is done. If __helptext is defined but empty no helptext
will be shown.

Logging support still exists as it did before. The environment variables
LOG_LEVEL and NO_COLOR are supported just as they were before.
2016-11-09 10:03:00 +01:00
Manuel Streuhofer
d2195eee3c mention the used license in each script header (#60)
turns out that the README.md explains that "... licensed under MIT ...
the LICENSE does not have to be bundled as long as ..." but the scripts
themselfs don't mention any license.

fixed that by adding a one line mention of the used license and the two
lines explaining that the header comments have to stay intact.
2016-11-08 21:15:46 +01:00
Kevin van Zonneveld
9928ef16d7 Update version 2016-11-08 13:07:29 +01:00
Manuel Streuhofer
f82bbe59b0 better logging. support for multiple lines. (#57)
* better logging: support for multiple lines

* renamed logging function from _fmt to __b3bp_log

* adding example to show how multiline logging works

the main idea is to be able to log e.g. the output of a command and
b3bp taking care of splitting and prefixing every line.

* simplified code, removed hacky space-at-EOL
2016-11-08 13:03:26 +01:00
Manuel Streuhofer
4445c181bb cleanup environment variables (#58)
all internally used variable names (e.g. the ones used while parsing
__usage and running the getopts loop) start with '__b3bp_tmp'. This
makes it easy to unset them all after the work is done.

additional bugfix: run getopts only if any options were actually
specified in __usage
2016-11-08 13:02:37 +01:00
Kevin van Zonneveld
35b51072b3 No more os detection (#41) 2016-06-24 13:12:41 +02:00
Kevin van Zonneveld
03a2ec5adf Better OS detection (#39) 2016-06-23 16:20:45 +02:00
Kevin van Zonneveld
818d7c81c7 Return Windows as OS when under Git Bash (?) #32 2016-06-22 09:52:38 +02:00
Kevin van Zonneveld
64488e569a For delete-key-friendliness, bundle the commandline definition block along with its parser 2016-06-21 13:49:11 +02:00
Kevin van Zonneveld
e0aadaf50c Comment each set with a single line 2016-06-21 13:48:37 +02:00
Kevin van Zonneveld
008face7c8 Less verbose header comments 2016-06-21 13:48:08 +02:00
Kevin van Zonneveld
4926bbc942 For delete-key-friendliness, don't crash on undeclared help vars 2016-06-21 13:38:47 +02:00
Kevin van Zonneveld
649b5a0f44 Introduce errtrace, which is on by default (BREAKING) 2016-06-21 13:36:48 +02:00
Kevin van Zonneveld
5ee427eef5 Allow adding a help that is not parsed. See #24 2016-06-21 12:30:12 +02:00
Kevin van Zonneveld
ae230acc3b Add best practice of using __double_underscore_prefixed_vars 2016-06-21 10:21:00 +02:00
Kevin van Zonneveld
18525f72da Make the license less restrictive. See #14 (#28)
* Make the license less restrictive. See #14

So that people can use _just_ main.sh without bothering with also
distributing the license

* Add license update to changelog

* Add a comment about expansion, see #26

* Use an unmodified MIT License, with the more permissive clause inside the code

As modifying the MIT License will needlessly (but rightfully) cause
suspicion

* Credit @bravo-kernel for his feedback

* Fix another typo

* Reword copyright
2016-06-20 09:57:31 +02:00
Kevin van Zonneveld
12f1013611 Credit @gdevenyi for his testing and suggestions 2016-06-19 13:17:52 +02:00
Kevin van Zonneveld
d70312e916 Add a comment about expansion, see #26 2016-06-19 13:13:38 +02:00
Kevin van Zonneveld
fc7802d707 Respect --no-color by setting the NO_COLOR flag in main.sh. Fixes #25. thx @gdevenyi 2016-06-19 13:06:53 +02:00
Kevin van Zonneveld
8687e384eb Split out changelog into separate file, credit @rouson for the FAQ 2016-03-03 12:45:07 +01:00
Izaak Beekman
a86d8d82b1
Mangle long-option names to allow dashes
Fixes problem where long options with dashes, like `--no-color` were
 broken. This was due to the fact that bash variable names must match
 `[_a-zA-Z][_0-9a-zA-Z]*` and the usage parsing and option handling was
 trying to create variables with dashes in their names. Short of
 employing Bash4 associative arrays, "name mangling" seemed like the
 best solution to this problem.

Solution: map dashes to underscores when creating bash variables in the
script that correspond to long option flags. The downside of this is
that `--no_color` and `--no-color` will collide, but users expecting to
use options that are identical except one has an underscore and the
other has a dash deserve the ensuing confusion.
2016-02-19 23:25:09 -05:00
Kevin van Zonneveld
db690268ea Whitespace 2016-02-17 13:46:05 +01:00
Kevin van Zonneveld
366d8c7c9c Update version 2016-02-17 13:41:46 +01:00
Kevin van Zonneveld
67f2eafc81 Update version 2016-02-17 09:53:20 +01:00
Kevin van Zonneveld
c3297e4a7a Better versioning 2016-02-17 09:35:59 +01:00
Kevin van Zonneveld
2019c5146a Upgrade version 2016-02-16 22:23:28 +01:00
Kevin van Zonneveld
d365e8dcea Allow disabling colors via NO_COLOR environment variable 2016-02-16 22:19:40 +01:00
Kevin van Zonneveld
915f858d5e Add __os magic var 2016-02-16 22:19:08 +01:00
Kevin van Zonneveld
cbe70aa80e Put comments on own line 2016-02-16 22:09:28 +01:00
Kevin van Zonneveld
ff907092a3 Document caveats 2016-02-16 22:08:27 +01:00
Kevin van Zonneveld
56721e9cd5 Add test for longopt parsing 2016-02-16 22:05:11 +01:00
Kevin van Zonneveld
df3d535ab1 Make long option parsing work on OSX's BSD awk 20070501 2016-02-16 21:59:38 +01:00
Kevin van Zonneveld
2196cc4411 Add __base magic var 2016-02-16 21:58:25 +01:00
Kevin van Zonneveld
90ad85f419 Port back more refined colorscheme from @arathai's fork 2016-02-16 21:24:41 +01:00
Kevin van Zonneveld
9935335ee8 Add @zbeekman as an author 2016-02-16 20:53:59 +01:00