Labrador Bash library. Collection of functions and libraries that I deem useful for working with Bash.
Kindly feel free to have converstations and ask questions on Github discussion and report bugs using Github issue.
Check https://kamilcuk.github.io/L_lib/ for the generated documentation.
The library is one file. Download the latest release from github and put in your PATH:
mkdir -vp ~/.local/bin/
curl -o ~/.local/bin/L_lib.sh https://raw.githubusercontent.com/Kamilcuk/L_lib/refs/heads/v0/bin/L_lib.sh
export PATH=~/.local/bin:$PATH
You can use the library with:
. L_lib.sh
You can test the library without installing with:
( . <(curl https://raw.githubusercontent.com/Kamilcuk/L_lib/refs/heads/v0/bin/L_lib.sh) && L_argparse -- -v -- arg ---- -v world hello && echo "$arg" "$v" )
Below is some list with some of the library features. The library contains much more.
- argument parsing in Bash with short, long optiong, subparsers, sub-function support and shell completion like
L_argparse
- logging library with levels and configurable output and filtering like
L_log_configure
L_info
L_logrun
L_run
- pretty function stack printing usually on ERR trap like
L_print_traceback
- execute an action on EXIT, any terminating signal or RETURN trap of any function like
L_finally
- create temporary directory and cd to it for the duration of a function with auto removal after return like
L_with_cd
L_with_cd_tmpdir
- create unidirectional connected two file descriptors like
L_pipe
- create and manage multiple coprocesses with separate file descriptors for stdin and stdout like
L_proc_popen
L_proc_communicate
L_proc_kill
- temporary enable or disable
set -x
for the duration of a command likeL_setx
L_unsetx
- easily sort a Bash arrays containing any characters like
L_sort
- failure handling utilities like
L_assert
L_die
L_check
L_panic
- variables holding color codes depending on terminal support like
L_color_detect
$L_RED
$L_BLUE
- checking Bash features and version like
$L_BASH_VERSION
$L_HAS_BASH4_0
$L_HAS_COMPGEN_V
$L_HAS_WAIT_N
- waiting on multiple PIDs with a timeout and collecting all exit codes like
L_wait
- simplify storing exit status of a command into a variable like
L_exit_to
L_exit_to_10
- help with path operations, with PATH or PYTHONPATH manipulation like
L_stem
L_dir_is_empty
L_path_append
L_relative_to
- string utilities like
L_strip
L_strupper
L_strstr
L_html_escape
L_urlencode
- split string without remote execution and understant
$''
sequences likeL_str_split
- templating output like
L_percent_format
L_fstring
- JSON escape like
L_json_escape
- Cache commands execution with ttl in memory or file like
L_cache
L_cache_decorate
- Easy writing function utilities by supporting
-v <var>
option or extracting comment before function likeL_handle_v_scalar
L_func_help
L_func_usage_error
L_decorate
- all supports any Bash versions from 3.2 to latest with portability funtions like
L_readarray
L_epochrealtime_usec
L_compgen
L_*
prefix for public symbols._L_*
prefix for private symbols, including local variables in functions taking a namereference.- Upper case used for global scope readonly variables.
- Lower case used for functions and user mutable variables
- Snake case for everything.
- The option
-v <var>
is used to store the result in a variable instead of printing it.- This follows the convention of
printf -v <var>
. - Without the
-v
option, the function outputs the elements on lines to stdout. - Associated function with
_v
suffix store the result in a hardcoded scratch variableL_v
.
- This follows the convention of
LGPL