Skip to content

Instantly share code, notes, and snippets.

View CoryG89's full-sized avatar

Cory Gross CoryG89

View GitHub Profile
@CoryG89
CoryG89 / jq
Last active June 19, 2023 22:34
Wrapper around jq that automatically includes all jq modules found in the module search path
#!/usr/bin/env bash
function main() {
local JQ_PREFIX="${JQ_PREFIX:-"$HOME/.local"}"
local JQ_BIN="${JQ_BIN:-"$JQ_PREFIX/bin/jq"}"
local JQ_LIB="${JQ_LIB:-"$JQ_PREFIX/lib/jq"}"
local JQ_MODULE_INCLUDES=""
for module in "$JQ_LIB"/*.jq; do
JQ_MODULE_INCLUDES="$JQ_MODULE_INCLUDES include "'"'"$(basename "$module" | sed -E 's/\.jq$//g')"'";'
@CoryG89
CoryG89 / bash-args.sh
Created October 14, 2020 15:29
Best Way to Parse Arguments in Bash
#!/usr/bin/env bash
# Works both inside of a function as shown here and outside of a function for script arguments
main() {
POSITIONAL_ARGS=""
while (( "$#" )); do
case "$1" in
-b|--boolean-flag)
BOOLEAN_FLAG=1