Skip to content

Commit a1c8bb2

Browse files
philiplNiklas Haas
authored andcommitted
{zsh,bash}-completion: use config when autocompleting profiles
We were over-enthusiastic when introducing --no-config into the autocompletions. When autocompleting profiles, you actually need the config, because that's where the profiles come from. zsh is untested - I don't use it.
1 parent f3df6f5 commit a1c8bb2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

etc/_mpv.zsh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ case $state in
192192

193193
parse-help-*)
194194
local option_name=${state#parse-help-}
195+
local no_config="--no-config"
195196
# Can't do non-capturing groups without pcre, so we index the ones we want
196197
local pattern name_group=1 desc_group=2
197198
case $option_name in
@@ -203,6 +204,8 @@ case $state in
203204
# but would break if a profile name contained spaces. This stricter one
204205
# only breaks if a profile name contains tabs.
205206
pattern=$'^\t([^\t]*)\t(.*)'
207+
# We actually want config so we can autocomplete the user's profiles
208+
no_config=""
206209
;;
207210
*)
208211
pattern=$'^[ \t]+(--'${option_name}$'=)?([^ \t]+)[ \t]*[-:]?[ \t]*(.*)'
@@ -211,7 +214,7 @@ case $state in
211214
esac
212215
local -a values
213216
local current
214-
for current in "${(@f)$($~words[1] --no-config --${option_name}=help)}"; do
217+
for current in "${(@f)$($~words[1] ${no_config} --${option_name}=help)}"; do
215218
[[ $current =~ $pattern ]] || continue;
216219
local name=${match[name_group]//:/\\:} desc=${match[desc_group]}
217220
if [[ -n $desc ]]; then

etc/mpv.bash-completion

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ _mpv_get_args()
2626
local partial="$2"
2727
local type=$(echo "$doc" | awk '{print $2;}')
2828

29+
# We special-case profiles to ensure we read the config
2930
if [ "$1" = "--show-profile" ]; then
30-
# This is a special case
31+
type="ShowProfile"
32+
elif [ "$1" = "--profile" ]; then
3133
type="Profile"
3234
fi
3335

@@ -59,7 +61,11 @@ _mpv_get_args()
5961
candidates+=("help")
6062
;;
6163
Profile)
62-
candidates=($(mpv --no-config $1= | grep -v ':' | awk '{print $1;}'))
64+
candidates=($(mpv $1=help | grep -v ':' | awk '{print $1;}'))
65+
candidates+=("help")
66+
;;
67+
ShowProfile)
68+
candidates=($(mpv $1= | grep -v ':' | awk '{print $1;}'))
6369
;;
6470
*)
6571
# There are other categories; some of which we could do something smarter

0 commit comments

Comments
 (0)