2020-01-09 03:09:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of mpv.
|
|
|
|
#
|
|
|
|
# mpv is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# mpv is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2020-02-08 16:59:56 +00:00
|
|
|
# Cache all the mpv options
|
2023-07-18 08:51:51 +00:00
|
|
|
_mpv_options=$(mpv --no-config --list-options)
|
2020-02-08 16:59:56 +00:00
|
|
|
|
2020-01-09 03:09:14 +00:00
|
|
|
_mpv_get_args()
|
|
|
|
{
|
2020-02-08 16:59:56 +00:00
|
|
|
local doc=$(echo "$_mpv_options" | grep -E "^\\s*$1\\s")
|
2020-01-09 03:09:14 +00:00
|
|
|
local partial="$2"
|
|
|
|
local type=$(echo "$doc" | awk '{print $2;}')
|
|
|
|
|
2023-09-02 23:00:34 +00:00
|
|
|
# We special-case profiles to ensure we read the config
|
2020-01-09 03:09:14 +00:00
|
|
|
if [ "$1" = "--show-profile" ]; then
|
2023-09-02 23:00:34 +00:00
|
|
|
type="ShowProfile"
|
|
|
|
elif [ "$1" = "--profile" ]; then
|
2020-01-09 03:09:14 +00:00
|
|
|
type="Profile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
declare -a candidates
|
|
|
|
case $type in
|
|
|
|
String)
|
2021-09-05 20:30:59 +00:00
|
|
|
if echo "$doc" | grep -q '\[file\]' ; then
|
2020-01-09 03:09:14 +00:00
|
|
|
if [ "$cur" = '=' ]; then
|
|
|
|
# Without this, _filedir will try and complete files starting with '='
|
|
|
|
cur=""
|
|
|
|
fi
|
2021-09-05 20:30:59 +00:00
|
|
|
_filedir 2>/dev/null || COMPREPLY=($(compgen -f))
|
2020-01-09 03:09:14 +00:00
|
|
|
return 0
|
|
|
|
else
|
2023-09-02 17:42:47 +00:00
|
|
|
candidates=($(mpv --no-config $1=help | grep -v ':' | awk '{print $1;}'))
|
2020-01-09 03:09:14 +00:00
|
|
|
candidates+=("help")
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
Flag)
|
|
|
|
candidates=("yes" "no" "help")
|
|
|
|
;;
|
2020-02-08 17:31:47 +00:00
|
|
|
Choices:|Object)
|
2023-09-02 17:42:47 +00:00
|
|
|
candidates=($(mpv --no-config $1=help | grep -v ':' | awk '{print $1;}'))
|
2020-01-09 03:09:14 +00:00
|
|
|
candidates+=("help")
|
|
|
|
;;
|
|
|
|
Image)
|
2023-09-02 17:42:47 +00:00
|
|
|
candidates=($(mpv --no-config $1=help))
|
2020-01-09 03:09:14 +00:00
|
|
|
candidates=("${candidates[@]:2}")
|
|
|
|
candidates+=("help")
|
|
|
|
;;
|
|
|
|
Profile)
|
2023-09-02 23:00:34 +00:00
|
|
|
candidates=($(mpv $1=help | grep -v ':' | awk '{print $1;}'))
|
|
|
|
candidates+=("help")
|
|
|
|
;;
|
|
|
|
ShowProfile)
|
|
|
|
candidates=($(mpv $1= | grep -v ':' | awk '{print $1;}'))
|
2020-01-09 03:09:14 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# There are other categories; some of which we could do something smarter
|
|
|
|
# about, with enough work.
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=($(compgen -W "${candidates[*]}" -- "${partial}"))
|
|
|
|
if [ ${#COMPREPLY[@]} -gt 1 ]; then
|
|
|
|
compopt -o nospace mpv
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-08 16:59:56 +00:00
|
|
|
# This regex detects special options where we don't want an '=' appended
|
2023-07-18 08:50:09 +00:00
|
|
|
_mpv_special_regex='\s(Flag.*\[not in config files\]|Print)'
|
|
|
|
_mpv_skip_regex='\sremoved \[deprecated\]'
|
|
|
|
_mpv_regular_options=($(echo "$_mpv_options" | grep -vE "$_mpv_skip_regex" | \
|
|
|
|
grep -vE "$_mpv_special_regex" | awk '{print "\\"$1;}' | grep '\--'))
|
|
|
|
_mpv_special_options=($(echo "$_mpv_options" | grep -vE "$_mpv_skip_regex" | \
|
|
|
|
grep -E "$_mpv_special_regex" | awk '{print "\\"$1;}' | grep '\--'))
|
2020-02-08 16:59:56 +00:00
|
|
|
|
2020-01-09 03:09:14 +00:00
|
|
|
_mpv()
|
|
|
|
{
|
|
|
|
compopt +o nospace mpv
|
|
|
|
|
|
|
|
# _filedir requires the current candidate be in $cur
|
|
|
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
|
|
|
local prev=${COMP_WORDS[((COMP_CWORD - 1))]}
|
|
|
|
|
|
|
|
if [ "$cur" = '=' ]; then
|
|
|
|
# If the current word is '=' then we are looking for an argument for the
|
|
|
|
# option specified by the previous word.
|
|
|
|
_mpv_get_args "$prev"
|
|
|
|
elif [ "$prev" = '=' ]; then
|
|
|
|
# If the previous word is '=' then we are completing an argument for the
|
|
|
|
# option specified by the word before the '='.
|
|
|
|
local prevprev=${COMP_WORDS[((COMP_CWORD - 2))]}
|
|
|
|
_mpv_get_args "$prevprev" "$cur"
|
|
|
|
else
|
|
|
|
case $cur in
|
|
|
|
-*)
|
2020-02-08 16:59:56 +00:00
|
|
|
COMPREPLY=($(compgen -W "${_mpv_regular_options[*]}" -S '=' -- "${cur}"))
|
2020-01-09 03:09:14 +00:00
|
|
|
local normal_count=${#COMPREPLY[@]}
|
2020-02-08 16:59:56 +00:00
|
|
|
COMPREPLY+=($(compgen -W "${_mpv_special_options[*]}" -- "${cur}"))
|
2020-01-09 03:09:14 +00:00
|
|
|
if [ $normal_count -gt 0 -o ${#COMPREPLY[@]} -gt 1 ]; then
|
|
|
|
compopt -o nospace mpv
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2021-09-05 20:30:59 +00:00
|
|
|
_filedir 2>/dev/null || COMPREPLY=($(compgen -f))
|
2020-01-09 03:09:14 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _mpv mpv
|