Generating all xdg-mime commands: Difference between revisions

From Notes to self
Jump to navigation Jump to search
No edit summary
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
This generates the xdg-mime commands for each .desktop files and the mimetypes they contain:<pre>
This generates the xdg-mime commands for each .desktop files and all mimetypes they contain:<pre>
find /usr/share/applications ~/.local/share/applications \
find /usr/share/applications ~/.local/share/applications \
   -iname '*.desktop' -print0 | while IFS= read -r -d $'\0' d; do
   -iname '*.desktop' -print0 | while IFS= read -r -d $'\0' d; do
     for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do
     for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do
         echo xdg-mime default "'$d'" "'$m'"
         echo xdg-mime default "'${d##/*/}'" "'$m'"
     done
     done
done
done
Line 9: Line 9:


Suggested on https://unix.stackexchange.com/a/361705
Suggested on https://unix.stackexchange.com/a/361705
For example to generate commands that make
* zathura
* geeqie
* nvim
* mpv
* onlyoffice-desktopeditors
* vifm
* qutebrowser
* cr3
preferred applications, run<pre>
for p in cr3 qutebrowser vifm onlyoffice-desktopeditors mpv nvim geeqie zathura; do
  grep "$p" fl | grep -v "zathura-pdf-poppler"
done
</pre>
where <code>fl</code> is the file obtained via the above command. Note that the order of applications in the cycle is reversed.


[[Category: Linux]]
[[Category: Linux]]

Latest revision as of 15:18, 29 October 2022

This generates the xdg-mime commands for each .desktop files and all mimetypes they contain:

find /usr/share/applications ~/.local/share/applications \
  -iname '*.desktop' -print0 | while IFS= read -r -d $'\0' d; do
    for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do
        echo xdg-mime default "'${d##/*/}'" "'$m'"
    done
done

Suggested on https://unix.stackexchange.com/a/361705

For example to generate commands that make

  • zathura
  • geeqie
  • nvim
  • mpv
  • onlyoffice-desktopeditors
  • vifm
  • qutebrowser
  • cr3

preferred applications, run

for p in cr3 qutebrowser vifm onlyoffice-desktopeditors mpv nvim geeqie zathura; do
  grep "$p" fl | grep -v "zathura-pdf-poppler"
done

where fl is the file obtained via the above command. Note that the order of applications in the cycle is reversed.