summaryrefslogtreecommitdiffstats
path: root/etc/mpv.bash-completion
diff options
context:
space:
mode:
Diffstat (limited to 'etc/mpv.bash-completion')
-rw-r--r--etc/mpv.bash-completion61
1 files changed, 45 insertions, 16 deletions
diff --git a/etc/mpv.bash-completion b/etc/mpv.bash-completion
index 60c1cabd51..4892d0e52b 100644
--- a/etc/mpv.bash-completion
+++ b/etc/mpv.bash-completion
@@ -17,33 +17,39 @@
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
#
-# Cache all the mpv options
-_mpv_options=$(mpv --list-options)
+_mpv_options()
+{
+ if [ -z ${_mpv_options_cache+x} ]; then
+ _mpv_options_cache=$(mpv --no-config --list-options)
+ fi
+ echo "$_mpv_options_cache"
+}
_mpv_get_args()
{
- local doc=$(echo "$_mpv_options" | grep -E "^\\s*$1\\s")
+ local doc=$(_mpv_options | grep -E "^\\s*$1\\s")
local partial="$2"
local type=$(echo "$doc" | awk '{print $2;}')
+ # We special-case profiles to ensure we read the config
if [ "$1" = "--show-profile" ]; then
- # This is a special case
+ type="ShowProfile"
+ elif [ "$1" = "--profile" ]; then
type="Profile"
fi
declare -a candidates
case $type in
String)
- echo "$doc" | grep -q '\[file\]'
- if [ $? -eq 0 ]; then
+ if echo "$doc" | grep -q '\[file\]' ; then
if [ "$cur" = '=' ]; then
# Without this, _filedir will try and complete files starting with '='
cur=""
fi
- _filedir
+ _filedir 2>/dev/null || COMPREPLY=($(compgen -f))
return 0
else
- candidates=($(mpv $1=help | grep -v ':' | awk '{print $1;}'))
+ candidates=($(mpv --no-config $1=help | grep -v ':' | awk '{print $1;}'))
candidates+=("help")
fi
;;
@@ -51,15 +57,19 @@ _mpv_get_args()
candidates=("yes" "no" "help")
;;
Choices:|Object)
- candidates=($(mpv $1=help | grep -v ':' | awk '{print $1;}'))
+ candidates=($(mpv --no-config $1=help | grep -v ':' | awk '{print $1;}'))
candidates+=("help")
;;
Image)
- candidates=($(mpv $1=help))
+ candidates=($(mpv --no-config $1=help))
candidates=("${candidates[@]:2}")
candidates+=("help")
;;
Profile)
+ candidates=($(mpv $1=help | grep -v ':' | awk '{print $1;}'))
+ candidates+=("help")
+ ;;
+ ShowProfile)
candidates=($(mpv $1= | grep -v ':' | awk '{print $1;}'))
;;
*)
@@ -74,9 +84,28 @@ _mpv_get_args()
}
# This regex detects special options where we don't want an '=' appended
-_mpv_special_regex='Flag.*\[not in config files\]|Print'
-_mpv_regular_options=($(echo "$_mpv_options" | grep -v -E "$_mpv_special_regex" |awk '{print "\\"$1;}' | grep '\--'))
-_mpv_special_options=($(echo "$_mpv_options" | grep -E "$_mpv_special_regex" |awk '{print "\\"$1;}' | grep '\--'))
+_mpv_special_regex='\s(Flag.*\[not in config files\]|Print)'
+_mpv_skip_regex='\sremoved \[deprecated\]'
+
+_mpv_regular_options()
+{
+ if [ -z ${_mpv_regular_options_cache+x} ]; then
+ _mpv_regular_options_cache=($(_mpv_options | grep -vE "$_mpv_skip_regex" | \
+ grep -vE "$_mpv_special_regex" | awk '{print "\\"$1;}' | grep '\--'))
+ _mpv_regular_options_cache="${_mpv_regular_options_cache[*]}"
+ fi
+ echo "$_mpv_regular_options_cache"
+}
+
+_mpv_special_options()
+{
+ if [ -z ${_mpv_special_options_cache+x} ]; then
+ _mpv_special_options_cache=($(_mpv_options | grep -vE "$_mpv_skip_regex" | \
+ grep -E "$_mpv_special_regex" | awk '{print "\\"$1;}' | grep '\--'))
+ _mpv_special_options_cache="${_mpv_special_options_cache[*]}"
+ fi
+ echo "$_mpv_special_options_cache"
+}
_mpv()
{
@@ -98,15 +127,15 @@ _mpv()
else
case $cur in
-*)
- COMPREPLY=($(compgen -W "${_mpv_regular_options[*]}" -S '=' -- "${cur}"))
+ COMPREPLY=($(compgen -W "$(_mpv_regular_options)" -S '=' -- "${cur}"))
local normal_count=${#COMPREPLY[@]}
- COMPREPLY+=($(compgen -W "${_mpv_special_options[*]}" -- "${cur}"))
+ COMPREPLY+=($(compgen -W "$(_mpv_special_options)" -- "${cur}"))
if [ $normal_count -gt 0 -o ${#COMPREPLY[@]} -gt 1 ]; then
compopt -o nospace mpv
fi
;;
*)
- _filedir
+ _filedir 2>/dev/null || COMPREPLY=($(compgen -f))
;;
esac
fi