diff --git a/completions/xdg-mime b/completions/xdg-mime index 44b50968698..39d784194cf 100644 --- a/completions/xdg-mime +++ b/completions/xdg-mime @@ -2,9 +2,25 @@ _xdg_mime_mimetype() { - COMPREPLY+=($(compgen -S / -W 'application audio font image message model - multipart text video' -- "$cur")) - [[ ${COMPREPLY-} == */ ]] && compopt -o nospace + local d i + local -a arr + for d in /usr/share/mime /usr/local/share/mime; do + arr=($( + command cd "$d" 2>/dev/null || exit 1 + compgen -f -o plusdirs -X "!*.xml" -- "$cur" + )) || continue + for i in "${!arr[*]}"; do + case ${arr[i]} in + packages*) unset -v "arr[i]" ;; # not a MIME type dir + *.xml) arr[i]=${arr[i]%.xml} ;; + */*) ;; + *) arr[i]+=/ ;; + esac + done + ((${#arr[@]})) && + COMPREPLY+=("${arr[@]}") + done + [[ ${COMPREPLY-} != */ ]] || compopt -o nospace } _xdg_mime() @@ -31,7 +47,8 @@ _xdg_mime() COMPREPLY=($(compgen -W 'filetype default' -- "$cur")) return fi - case ${words[2]} in # TODO and args == 3 (takes only one arg!) + ((args == 3)) || return + case ${words[2]} in filetype) _filedir ;; default) _xdg_mime_mimetype ;; esac diff --git a/test/t/test_xdg_mime.py b/test/t/test_xdg_mime.py index 432be0676bd..b91e75a0b41 100644 --- a/test/t/test_xdg_mime.py +++ b/test/t/test_xdg_mime.py @@ -19,10 +19,14 @@ def test_3(self, completion): def test_4(self, completion): assert completion - @pytest.mark.complete("xdg-mime default foo.desktop ") + @pytest.mark.complete("xdg-mime default foo.desktop ", require_cmd=True) def test_5(self, completion): assert completion @pytest.mark.complete("xdg-mime install --mode ") def test_6(self, completion): assert completion + + @pytest.mark.complete("xdg-mime query filetype foo ") + def test_filetype_one_arg(self, completion): + assert not completion diff --git a/test/test-cmd-list.txt b/test/test-cmd-list.txt index ae2f174f049..c8e236dbfca 100644 --- a/test/test-cmd-list.txt +++ b/test/test-cmd-list.txt @@ -429,6 +429,7 @@ wol wsimport wtf wvdial +xdg-mime xdg-settings xev xfreerdp