hledger/shell-completion/parse-options.sh
Vladimir Zhelezov ac143aff6b Do not use set -e in helper shell scripts
It is not a substitute for proper error checking, it can easily cause
more trouble than good and it would be a burden for contributors and a
source for potential misbehavior. See this take on the topic for
example: http://mywiki.wooledge.org/BashFAQ/105
2021-02-28 08:33:18 +01:00

22 lines
584 B
Bash
Executable File

#!/usr/bin/env bash
# Parse hledger's help and output long options. Do not propose single letter
# completions. Options requiring an argument make that explicit by appending the
# equal sign (=)
set -uo pipefail
declare subcommand=${1:-}
declare hledgerArgs=(--help)
[[ -n $subcommand ]] && hledgerArgs=("$subcommand" "${hledgerArgs[@]}")
hledger "${hledgerArgs[@]}" |
sed -rn '/^\s+-/p' |
sed -rn 's/^\s{1,4}(-.)?\s{1,4}(--[a-zA-Z][-_a-zA-Z0-9]+=?).*/\2/p' |
sort -u
# Local Variables:
# mode: sh
# sh-basic-offset: 4
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et