From 3728f8d69425be7db6ccce42a120ed1bcd61907c Mon Sep 17 00:00:00 2001 From: bidiudiu Date: Sun, 11 Oct 2026 13:15:39 +0800 Subject: [PATCH] fix(rsync):Use the canonical command for alias completions. Fixes scop#1370 $1 can be a user alias, which is not expanded when used as a command name through a parameter expansion. Query the real command instead so that aliases produce the same options. --- completions-core/rsync.bash | 4 ++-- test/t/test_rsync.py | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/completions-core/rsync.bash b/completions-core/rsync.bash index 8042a3cfae3..fa5eda320ac 100644 --- a/completions-core/rsync.bash +++ b/completions-core/rsync.bash @@ -85,7 +85,7 @@ _comp_cmd_rsync() # meaning before v3.2.0) contain the following unusual line in # --help: # "(-h) --help show this help (-h is --help only if used alone)" - if _comp_compgen -Rv tmp help - <<<"$("$1" --help 2>&1 | command sed -e 's/^([^)]*)//')"; then + if _comp_compgen -Rv tmp help - <<<"$(command rsync --help 2>&1 | command sed -e 's/^([^)]*)//')"; then _comp_compgen -- -W '"${tmp[@]}" --daemon --old-d{,irs} @@ -106,7 +106,7 @@ _comp_cmd_rsync() fi done if [[ $shell == ssh ]]; then - local rsync_version=$("$1" --version 2>/dev/null | + local rsync_version=$(command rsync --version 2>/dev/null | command sed -n '1s/.*rsync *version \([0-9.]*\).*/\1/p') _comp_cmd_rsync__vercomp "$rsync_version" "3.2.4" if (($? == 2)); then diff --git a/test/t/test_rsync.py b/test/t/test_rsync.py index ee4304b1e71..03574932bb1 100644 --- a/test/t/test_rsync.py +++ b/test/t/test_rsync.py @@ -1,6 +1,6 @@ import pytest -from conftest import assert_bash_exec, assert_complete +from conftest import assert_bash_exec, assert_complete, is_bash_type @pytest.mark.bashcomp(ignore_env=r"^[+-]_comp_cmd_scp__path_esc=") @@ -75,6 +75,32 @@ def test_remote_path_with_spaces(self, bash): or completion == r"\\\ in\\\ filename.txt" ) + def test_alias_options(self, bash): + """Options for a manually registered alias match the real command.""" + if not is_bash_type(bash, "rsync"): + pytest.skip("Command not found") + assert_bash_exec( + bash, + "alias _comp_test_rsync_alias=rsync", + ) + assert_bash_exec( + bash, + "complete -o nospace -F _comp_cmd_rsync _comp_test_rsync_alias", + ) + try: + expected = assert_complete(bash, "rsync --") + completion = assert_complete( + bash, + "_comp_test_rsync_alias --", + ) + assert completion == expected + finally: + assert_bash_exec( + bash, + "unalias _comp_test_rsync_alias; " + "complete -r _comp_test_rsync_alias 2>/dev/null || true", + ) + @pytest.mark.complete(r"rsync -na spaced\ ", cwd="scp") def test_local_path_with_spaces(self, completion): """This function tests xfunc _comp_xfunc_scp_compgen_local_files, which