@@ -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
0 commit comments