Skip to content

Commit d2fee26

Browse files
committed
fix(tmux): fix usage parsing with git master tmux
This fixes usage parsing for the changes in tmux/tmux@68ffe65 Tested against tmux 3.5a and faf2a448 (Merge branch 'obsd-master', 2025-05-12).
1 parent 9f5aedb commit d2fee26

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

completions/tmux

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ _comp_cmd_tmux__options()
162162
done
163163
}
164164
165+
# Complete arguments to a nested command.
166+
#
167+
# @param $1 the arg type of the command, e.g., command or shell-command
168+
# @param $2... args to the command, starting with the command itself, ending
169+
# before the current word to complete
170+
_comp_cmd_tmux__nested_arguments()
171+
{
172+
local arg_type="$1"
173+
shift
174+
_comp_cmd_tmux__log \
175+
"Attempting completion for arguments to '$1' of type '$arg_type'"
176+
177+
case $arg_type in
178+
command)
179+
_comp_cmd_tmux__subcommand "$@"
180+
;;
181+
esac
182+
}
183+
165184
# Complete arguments to a subcommand.
166185
#
167186
# @param $@ the subcommand followed by its args, ending before the current word
@@ -239,12 +258,28 @@ _comp_cmd_tmux__subcommand()
239258
# above.
240259
_comp_cmd_tmux__value "$subcommand" "$prev_arg_type"
241260
return
261+
elif [[ $arg_type == argument ]]; then
262+
# New-style usage after
263+
# https://github.com/tmux/tmux/commit/68ffe654990764ed5bdb7efb88e4d01b921fd3d5
264+
# (2025-04-09) ends in `argument ...`
265+
if ((usage_args_index == ${#args[@]} - 2)) &&
266+
[[ ${args[-1]-} == *("[")...*("]") ]]; then
267+
_comp_cmd_tmux__nested_arguments \
268+
"$prev_arg_type" \
269+
"${subcommand_args[@]:args_index-1}"
270+
return
271+
else
272+
_comp_cmd_tmux__log \
273+
"'tmux $subcommand' has unsupported 'argument' in usage"
274+
return
275+
fi
242276
elif [[ $arg_type == arguments ]]; then
243-
if [[ $prev_arg_type == command ]] &&
244-
((usage_args_index == ${#args[@]} - 1)); then
245-
# The usage ends in `command arguments`, so recurse to the new
246-
# subcommand.
247-
_comp_cmd_tmux__subcommand \
277+
# Old-style usage before
278+
# https://github.com/tmux/tmux/commit/68ffe654990764ed5bdb7efb88e4d01b921fd3d5
279+
# (2025-04-09) ends in `arguments`
280+
if ((usage_args_index == ${#args[@]} - 1)); then
281+
_comp_cmd_tmux__nested_arguments \
282+
"$prev_arg_type" \
248283
"${subcommand_args[@]:args_index-1}"
249284
return
250285
else

test/t/test_tmux.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ def test_option_without_value(self, completion):
7070
def test_option_multiple_without_value(self, completion):
7171
assert "new-session" in completion
7272

73+
# Tests for _comp_cmd_tmux__nested_arguments()
74+
75+
@pytest.mark.complete(
76+
"tmux bind-key C-a new-window -c ",
77+
cwd="shared/default",
78+
)
79+
def test_nested_arguments_tmux_subcommand(self, completion):
80+
assert completion == ["bar bar.d/", "foo.d/"]
81+
7382
# Tests for _comp_cmd_tmux__subcommand()
7483

7584
@pytest.mark.complete("tmux this-is-not-a-real-subcommand-i-hope ")
@@ -93,13 +102,6 @@ def test_subcommand_no_positional_arg_completion(self, completion):
93102
def test_subcommand_repetition(self, completion):
94103
assert completion == ["bar", "bar bar.d/", "foo", "foo.d/"]
95104

96-
@pytest.mark.complete(
97-
"tmux bind-key C-a new-window -c ",
98-
cwd="shared/default",
99-
)
100-
def test_subcommand_recursion(self, completion):
101-
assert completion == ["bar bar.d/", "foo.d/"]
102-
103105
@pytest.mark.complete("tmux source-file ", cwd="shared/default")
104106
def test_subcommand_positional_arg_1(self, completion):
105107
assert completion == ["bar", "bar bar.d/", "foo", "foo.d/"]

0 commit comments

Comments
 (0)