From 0db1486d2767e8cc74905a26d88b5c0c0c5556a2 Mon Sep 17 00:00:00 2001 From: Lee Bigelow Date: Mon, 22 Dec 2025 15:39:55 -0330 Subject: [PATCH 1/5] Add files via upload completion file for xdg-mime --- src/_xdg-mime | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/_xdg-mime diff --git a/src/_xdg-mime b/src/_xdg-mime new file mode 100644 index 0000000..62bc11d --- /dev/null +++ b/src/_xdg-mime @@ -0,0 +1,62 @@ +#compdef xdg-mime + +# Description: +# ZSH Completion for xdg-mime 1.2.1 from +# xdg-utils (https://gitlab.freedesktop.org/xdg/xdg-utils) +# +# Authors: +# ligelowbee@gmail.com + +_xdg-mime_query() { + _arguments \ + "1:Query Type:(( + filetype\:'Returns mime-type of a file' + default\:'Returns default application for a mime-type'))" \ + "*::arg:->args" + + case $line[1] in + filetype) _arguments '*: :_files' ;; + default) _arguments '*: :_mime_types' ;; + esac +} + +_xdg-mime() { + local line + local -A appdirs=( + /usr/share/applications + $HOME/.local/share/applications + ) + + _arguments -C \ + "--help[Show help info]" \ + "--version[Show version info]" \ + "--manual[Show manual page]" \ + "1:xdg-mime command:(query default install uninstall)" \ + "*::arg:->args" + + case $line[1] in + query) _xdg-mime_query ;; + default) + _arguments \ + "1:Application:_files -W '$appdirs' -g '*.desktop'" \ + '2: :_mime_types' + ;; + install) + _arguments \ + "--mode=[Install for user or system]: :(( + user\:'Install for this user only' + system\:'Install for all users'))" \ + "--novendor[Don't check mimetype-file for vendor prefix]" \ + '*:XML mimetypes file:_files -g "*.xml"' + ;; + uninstall) + _arguments \ + "--mode=[Uninstall for user or whole system]: :(( + user\:'Uninstall for this user only' + system\:'Uninstall for all users'))" \ + '*:XML mimetypes file:_files -g "*.xml"' + ;; + esac +} + +# vim: filetype=zsh expandtab softtabstop=2 tabstop=2 shiftwidth=2 From 64484169e2270eea79582fe5dd1f58fe5cdb36c9 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 23 Dec 2025 13:11:59 +0900 Subject: [PATCH 2/5] Add emacs local variables too --- src/_xdg-mime | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/_xdg-mime b/src/_xdg-mime index 62bc11d..c35d335 100644 --- a/src/_xdg-mime +++ b/src/_xdg-mime @@ -1,7 +1,7 @@ #compdef xdg-mime -# Description: -# ZSH Completion for xdg-mime 1.2.1 from +# Description: +# ZSH Completion for xdg-mime 1.2.1 from # xdg-utils (https://gitlab.freedesktop.org/xdg/xdg-utils) # # Authors: @@ -10,7 +10,7 @@ _xdg-mime_query() { _arguments \ "1:Query Type:(( - filetype\:'Returns mime-type of a file' + filetype\:'Returns mime-type of a file' default\:'Returns default application for a mime-type'))" \ "*::arg:->args" @@ -59,4 +59,10 @@ _xdg-mime() { esac } -# vim: filetype=zsh expandtab softtabstop=2 tabstop=2 shiftwidth=2 +# Local Variables: +# mode: Shell-Script +# sh-indentation: 2 +# indent-tabs-mode: nil +# sh-basic-offset: 2 +# End: +# vim: filetype=zsh expandtab softtabstop=2 tabstop=2 shiftwidth=2 From 2cff35a45d9d3c55b761cd02bb6d1ee42278045b Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 23 Dec 2025 13:12:45 +0900 Subject: [PATCH 3/5] Call completion function explicitly This avoid pressing tab twice to complete subcommand --- src/_xdg-mime | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_xdg-mime b/src/_xdg-mime index c35d335..7a278e8 100644 --- a/src/_xdg-mime +++ b/src/_xdg-mime @@ -59,6 +59,8 @@ _xdg-mime() { esac } +_xdg-mime "$@" + # Local Variables: # mode: Shell-Script # sh-indentation: 2 From 779f02a78b1e96004bc316db4bd5d1e03dec398c Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 23 Dec 2025 13:14:42 +0900 Subject: [PATCH 4/5] Fix appdirs type This should be array not associative array. And fix its usage too to pass it to _files correctly --- src/_xdg-mime | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_xdg-mime b/src/_xdg-mime index 7a278e8..2f28648 100644 --- a/src/_xdg-mime +++ b/src/_xdg-mime @@ -22,9 +22,9 @@ _xdg-mime_query() { _xdg-mime() { local line - local -A appdirs=( + local -a appdirs=( /usr/share/applications - $HOME/.local/share/applications + "$HOME/.local/share/applications" ) _arguments -C \ @@ -38,7 +38,7 @@ _xdg-mime() { query) _xdg-mime_query ;; default) _arguments \ - "1:Application:_files -W '$appdirs' -g '*.desktop'" \ + "1:Application:_files -W appdirs -g '*.desktop'" \ '2: :_mime_types' ;; install) From 7fb495cab52b0932b961fa66fb15cbb87916128d Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 23 Dec 2025 13:17:14 +0900 Subject: [PATCH 5/5] call completion function directly --- src/_xdg-mime | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_xdg-mime b/src/_xdg-mime index 2f28648..a9129ed 100644 --- a/src/_xdg-mime +++ b/src/_xdg-mime @@ -15,8 +15,8 @@ _xdg-mime_query() { "*::arg:->args" case $line[1] in - filetype) _arguments '*: :_files' ;; - default) _arguments '*: :_mime_types' ;; + filetype) _files ;; + default) _mime_types ;; esac }