1
mirror of https://github.com/mpv-player/mpv synced 2024-11-14 22:48:35 +01:00

bash completion: Allow completions to work without external functions

If bash_completion wasn't installed, _filedir wouldn't be defined which
led to all filename-based completions to error out. Specifically
autocompletion would fail when a filename was expected and when
bash_completion wasn't installed. Now we fall back to `compgen -f` if
_filedir fails. According to _filedir's comments, compgen doesn't
handle files with spaces well, but it is still better to complete most
files than none.
This commit is contained in:
Arthur Williams 2021-09-05 15:30:59 -05:00 committed by Philip Langdale
parent 8aef22e45d
commit 6f23aa0d3e

View File

@ -34,13 +34,12 @@ _mpv_get_args()
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;}'))
@ -106,7 +105,7 @@ _mpv()
fi
;;
*)
_filedir
_filedir 2>/dev/null || COMPREPLY=($(compgen -f))
;;
esac
fi