code/bash
2024-02-27 10:35:47 -05:00
..
README.org Add bash/README.org 2024-02-27 10:35:47 -05:00

Here is some code that I test trying to capture STDIN from a function and with wrapping a command with a logger

#!/usr/bin/env bash

alu-log-warn () {
    echo '{{ Color "192" "0" "  warn "}}' "$@" | gum format -t 'template' >&2
}


myfunc () {
    local in
    if [[ -z "$@" ]]
    then
        read in
    else
        in="$@"
    fi
    echo '{{ Color "86" "0" "  info "}}' "$in" | gum format -t 'template' >&2
}

extern-func () {

    echo 'I write to stdout'
    echo 'I write to stderr' >&2

}

# alu-log-warn "Testing calling the function"

# myfunc 'Testing testing 1 2 3'

# alu-log-warn "Testing piping to the function"

# echo 'Testing testing 1 2 3' | myfunc

alu-log-warn "Smoke test: Calling the function"
extern-func

alu-log-warn "Smoke test: Filtering stdout"
extern-func > /dev/null

alu-log-warn "Smoke test: Filtering stderr"
extern-func 2> /dev/null

alu-log-warn "Catching output"
extern-func 2> >(myfunc)