bash-completion: complete aliases and list actions like their target

Options like --sub-file are aliases for list actions like
--sub-files-append, which --list-options shows without a type, so
nothing was completed after them. Follow aliases to their target, and
complete typeless list actions like the list option they act on.

This makes --sub-file=, --audio-file=, --glsl-shader=, --script= etc.
complete files, --sub-files-append= etc. complete files when typed
directly, and other aliases like --fs= and --audio= complete the values
of their target.

Fixes #7955.
This commit is contained in:
shbernal
2026-10-12 19:18:40 +02:00
committed by Philip Langdale
parent 88eb9f2e73
commit 9d144e57b6
+16
View File
@@ -29,6 +29,22 @@ _mpv_get_args()
local partial="$2"
local type=$(echo "$doc" | awk '{print $2;}')
# Complete aliases like their target (e.g. --sub-file -> --sub-files-append)
local opt="$1"
if [ "$type" = "alias" ]; then
opt=--$(echo "$doc" | awk '{sub(/^--/, "", $4); print $4;}')
doc=$(_mpv_options | grep -E "^\\s*$opt\\s")
type=$(echo "$doc" | awk '{print $2;}')
fi
# List actions are listed without a type; complete them like the list option
if [ -z "$type" ]; then
local list=$(echo "$opt" | sed -E 's/-(add|append|del|pre|remove|set|toggle)$//')
if [ "$list" != "$opt" ]; then
doc=$(_mpv_options | grep -E "^\\s*$list\\s")
type=$(echo "$doc" | awk '{print $2;}')
fi
fi
# We special-case profiles to ensure we read the config
if [ "$1" = "--show-profile" ]; then
type="ShowProfile"