Skip to content

andis-sprinkis/xdg-open-simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

xdg-open-simple

xdg-open-simple is a minimal fork of the xdg-open (the default utility of opening files and URLs on many Linux & Unix-like desktop operating systems).

Properties of this fork

  • Not an attempt to reinvent how xdg-open works.

    Adheres to the XDG specifications "Desktop Entry Specification", "Association between MIME types and applications".

  • Some of the xdg-open features and behaviors have been removed:

    • Auto-forwarding target paths without a known MIME handler to a web browser. (Not in specifications.)

      Reason: Obfuscates that there is a missing MIME handler on the system. Often just results in creating needless target file copies in the downloads directory.

    • Handling the $BROWSER variable. (Not in specifications.)

      Reason: A legacy convention of setting the default web browser on some Linux systems. Redundant, overlaps with the core functionality of xdg-open.

    • Handling any mimeapps.list and Desktop file search paths that have been deprecated. (In specifications.)

    • Desktop environment specific integrations:

      • Auto-forwarding target paths to desktop environment specific file openers. (Not in specifications.)
      • Use of <lowercased DE name>-mimeapps.list (in specifications), <lowercased DE name>-mimeinfo.cache (not in specifications).

      Reason: Temporal work-arounds and data mappings are needed to support these, due to the lack of desktop environment vendor adherence to, or the lack of the definition in the XDG specifications. Not required for providing the core functionality of this tool.

    • Substituting Name (%c) and Icon (%i) field codes within the Exec key to pass program icon identifiers and localized program names to the applications. (In specifications.)

      Reason: Unlikely to be in use anymore. Out of the 100 Desktop files on my Linux system, none use these field codes.

  • Support of the relative target file paths and URLs has been added.

  • From xdg-utils system package substitutes only the xdg-open. Presence of xdg-utils is expected for mimeinfo.cache generation. A lot more concise than the original xdg-open. Retains the original applicable xdg-open exit codes.

Installation

Add this line to some shell initialization script (e.g. $HOME/.profile for Bash, $HOME/.zshenv for ZSH):

PATH="$HOME/.local/bin:$PATH"

Run:

mkdir -p "$HOME/.local/opt/" "$HOME/.local/bin"
git clone "https://github.com/andis-sprinkis/xdg-open-simple/" "$HOME/.local/opt/xdg-open-simple"
cd "$HOME/.local/bin"
ln -s "../opt/xdg-open-simple/xdg-open" "xdg-open"

Resources


How-to's

Tips for dealing with the Linux file-type vs. application associations. Not specific to this project itself - will work with the stock xdg-utils too.

Setting the user default file and URL associations

$HOME/.config/mimeapps.list:

[Default Applications]
x-scheme-handler/msteams=Teams.desktop
video/mp4=video.desktop
...

The system .desktop files are in /usr/share/applications.

A user custom file handler

$HOME/.local/share/applications/video.desktop:

[Desktop Entry]
Type=Application
Name=Video player
Exec=mpv --player-operation-mode=pseudo-gui -- %U

Printing the file MIME type

file --brief --dereference --mime-type ./image.jpg
image/jpeg

The URLs get the x-scheme-handler/* MIME type, with the URL prefix as the suffix.

Printing the known MIME types

find /usr/share/mime/ -type f -name '*.xml' | sed -e 's/\/usr\/share\/mime\///g' -e "s/\.xml$//g" | less
application/andrew-inset.xml
application/annodex.xml
application/appinstaller.xml
...

Preventing Mozilla Firefox from rewriting the user's mimeapps.list file

echo > "$HOME/.mozilla/firefox/PROFILE.default-release/handlers.json'

This clears the handlers.json file, which removes the downloaded file custom handlers configured in Firefox.