Skip to content

Commit

Permalink
mr: avoid herestrings, simplify command parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 17, 2020
1 parent eb93dde commit cf64492
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions completions/mr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ _mr()

help="$(PERLDOC_PAGER=cat PERLDOC=-otext "${1}" help 2>/dev/null)"

commands="$(awk '/\[options\]/ { print $3 }' <<<"${help}")"
commands="$(
printf %s "$help" | while read -r _ options cmd _; do
[[ $options != "[options]" ]] || printf "%s\n" "$cmd"
done
)"
# Split [online|offline] and remove `action` placeholder.
commands="${commands//@(action|[\[\|\]])/$'\n'}"
# Add standard aliases.
Expand Down Expand Up @@ -72,7 +76,7 @@ _mr()
esac

if [[ $cur == -* ]]; then
options="$(_parse_help - <<<"${help}")"
options="$(printf '%s\n' "$help" | _parse_help -)"
# Remove short options (all have compatible long options).
options="${options//-[a-z]$'\n'/}"
# Remove deprecated options.
Expand Down

0 comments on commit cf64492

Please sign in to comment.