A shell (bash- and zsh-compatible) library, largely for:
- logging (with colours)
- easier input (e.g. with defaults, single-keystroke, continuation, etc)
Put the file on your PATH and then use source g_lib.sh in your shell.
source g_lib.sh
g_opts ...
g_info ...
yorn ...
g_select ...
g_colr $colour $textSee source for what options are available.
-
g_info [ --pre "pre" ] "info-text"show timestamp, optional 'INFO' (see
g_opts info), then "info-text" coloured suitably -
g_warn [ --pre "pre" ] "warn-text"similar to
g_info(above): show timestamp, 'WARN', then "warn-text" coloured suitably - to STDERR -
g_err [ --pre "pre" ] "err-text"similar to
g_info(above): show timestamp, 'ERROR', then "err-text" coloured suitably - to STDERR -
g_die $exit_code [ --pre "pre" ] "die-text"run
g_errwith post-$exit_codeargs, thenexit $exit_code -
g_trace [ --pre "pre" ] "trace-text"similar to
g_info(above): show timestamp, 'TRACE', then "trace-text" coloured suitably - to STDERR -
g_colr [ -r ] $colour "text"Example:
g_colr cyan "this is output in colour"Output the text in colour - where colour is one of:
- `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan` or `white` - for bold versions of the colours, use one of: - uppercase - e.g. `BLACK` is grey - the prefix `bright_` - e.g. `bright_black` is grey - `bold` turns on bold for the current colour - `${foreground_colour}_on_${background_colour}` - e.g. `black_on_white`If text already has embedded colours, then the
-rflag can be used to re-apply colour after each embedded colour segment. e.g.g_colr -r cyan "cyan-before $(g_colr red "red-highlight") cyan-after" -
yorn "Continue"Ask a question and the single-keystroke answer (
y,n) returns in$yorn
A shell library for deploying files - e.g. using diff, install and prompting
(uses g_lib.sh, above).
Handles symlinks in a more verbose/clear manner.
source src_up.sh
src_up { --0755 | --install | --lines | --ln $ln_to | --mkdir | --verbose } [ -- ] $src $targetCopyright © 2018-2026, Geraint "Gedge" Edwards
Released under MIT license, see LICENSE for details.