I have got a set of scripts that all source some common context:
DEFAULT_PAGINATION=''
ownContext=$HOME/.config/exploitation/context.sh
if [ -f "$ownContext" ]; then
# shellcheck source=$HOME/.config/exploitation/context.sh
. "$ownContext"
fi
That way anybody can override the default config: some locations, help flags and in this case, pagination.
To automatically redirect to less, for instance, I have tried that:
# DEFAULT_PAGINATION is the default pagination tool (a program)
# OUTPUT_PAGINATION_FILE acts as an include guard, or contains a filename
if [ -n "$DEFAULT_PAGINATION" ] && [ -z "$OUTPUT_PAGINATION_FILE" ]; then
paginate() {
$DEFAULT_PAGINATION "$OUTPUT_PAGINATION_FILE" # paginate tempfile
}
trap paginate exit
OUTPUT_PAGINATION_FILE=$(mktemp)
export OUTPUT_PAGINATION_FILE
exec 1<&- # close stdout
exec 1<>"$OUTPUT_PAGINATION_FILE" # redirect stdout to a temp file
fi
and export DEFAULT_PAGINATION=less
in the other context file, but it doesn't work. Any idea ?
Plus, that solution does not allow export DEFAULT_PAGINATION="less +F"
and on the fly redirection. Is there a solution to do that ?
P.S. the bash
tag is intentionnal