Skip to content

Commit

Permalink
fix(rsync): hardcode two-character options
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 13, 2024
1 parent 009cf8b commit b074874
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions completions/rsync
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,27 @@ _comp_cmd_rsync()
awk 'sub(/^--?/,"--no-"){sub(/=$/,"");print}'
} | command grep -Exe "$(strings -d "$(type -P "$1")" 2>/dev/null | command sed -n '/[^-a-zA-Z0-9]/d;s/$/=?/;/^--[a-zA-Z]/p;s/^[a-zA-Z]/--&/p;s/^--no-/--/p')"
)"


# These options cannot be tested by "strings -d /path/to/rsync"
# because they are too short to extract using "strings". We
# manually generate them when rsync is likely to suppor the feature.
local -a hardcoded_options=()
# * "--compress-choice" and its synonyms "--cc" and "--zc" are
# available in rsync-3.2.0.
[[ " ${help_options[*]} " == *' --compress-choice= '* ]] &&
hardcoded_options+=(--cc= --zc=)
# * The short name "--zl" for "--compress-level" has been
# introduced in rsync-3.2.1. We here abuse the fact that
# another option "--early-info" is also introduced in
# rsync-3.2.1. We also confirm that rsync actually supports
# the feature by checking the longer option.
[[ " ${help_options[*]} " == *' --early-info= '* ]] &&
[[ " ${help_options[*]} " == *' --compress-level= '* ]] &&
hardcoded_options+=(--zl=)

_comp_compgen -- -W '$(printf '%s\n' "${help_options[@]}" \
"${confirmed_options[@]}" | sort -u)' -X '--no-OPTION'
"${confirmed_options[@]}" "${hardcoded_options[@]}" | \
sort -u)' -X '--no-OPTION'
fi
[[ ${COMPREPLY-} == *= ]] || compopt +o nospace
;;
Expand Down

0 comments on commit b074874

Please sign in to comment.