Collection of helpful functions for bash. Core functions are outlined below.
check_dependencies
Check whether multiple shell-commands are available
Arguments:
--commands <array>
The commands to be checked for availability
Default: ls chmod
Usage:
check_dependencies \
--commands "ls chmod"
check_dependency
Check whether a single shell-commands is available
Arguments:
--command <str>
The command to be checked for availability
Default: ls
Usage:
check_dependency \
--command "ls"
current_file
Determine the current file path, using
bash : ${BASH_SOURCE[0]}
zsh : ${(%):-%x}
Usage:
current_file
make_file_path
Create file from path, create path if it does not exist
Arguments:
--file <str>
The file to create the path for
Default: ~/path/to/file
Usage:
make_file_path \
--file "~/path/to/file"
normalize_path
Normalize a folder / file path
Arguments:
--path <str>
The path to normalize
Default: ~/path/to/file
Usage:
normalize_path \
--path "~/path/to/file"
read_from_file
Read a file.
Like `cat`, but returns empty string if file does not exist
Arguments:
--file <str>
The file to read from
Default: ~/path/to/file
Usage:
read_from_file \
--file "~/path/to/file"
bash_aux_log
Create log files based on the called function's name
Arguments:
--path <str>
The path to create the log files in
Default: .
--content <str>
The content to log
Default: Hello, world!
Usage:
bash_aux_log \
--path "." \
--content "Hello, world!"
read_non_blocking
Read input from stdin / pipe / user input, but don't wait for the input
Usage:
read_non_blocking