xdgctl: A Terminal Interface for Linux's XDG Default Application Management
#Dev

xdgctl: A Terminal Interface for Linux's XDG Default Application Management

Startups Reporter
4 min read

A new C-based TUI tool simplifies the often-convoluted process of setting default applications for file types and URL schemes on Linux desktops, replacing manual command-line work with a navigable interface.

Managing default applications on Linux desktops has long been a task of memorizing xdg-mime command syntax, editing mimeapps.list files, and manually placing .desktop entries in the correct directories. For users who live in the terminal, this process is especially cumbersome, requiring context switches to a GUI file manager or a series of precise terminal commands. A new project called xdgctl aims to bridge this gap by providing a terminal user interface (TUI) specifically designed for browsing and setting XDG default applications.

Built with C and leveraging the GLib/GIO libraries alongside the termbox2 terminal interface library, xdgctl presents a two-pane interface. The left pane lists application categories—such as Browsers, Text Editors, and Media Players—while the right pane displays the available applications for the selected category. The currently set default for any category is clearly marked with an asterisk (*). Navigation is handled with the arrow keys, and setting a new default is as simple as selecting an application and pressing Enter. This approach abstracts away the underlying complexity of the XDG specification, which defines how applications should be integrated into a desktop environment.

The tool addresses a specific pain point in the Linux ecosystem. While graphical desktop environments provide their own default application settings, these are often limited in scope or tied to a specific desktop shell (like GNOME or KDE). The XDG specifications are the universal standard, but their command-line interface is verbose. For instance, setting the default browser for HTTP and HTTPS links requires two separate commands: xdg-mime default brave.desktop x-scheme-handler/http and xdg-mime default brave.desktop x-scheme-handler/https. A user must also know the correct desktop file name (e.g., brave.desktop) and ensure it's in a location where the system can find it, typically /usr/share/applications/ or ~/.local/share/applications/. After adding or modifying a desktop file, the update-desktop-database command is often needed to register the changes.

xdgctl automates this discovery and selection process. It scans the standard application directories, parses the desktop entries to understand their capabilities (via the Categories and MimeType fields), and presents them in a logical, browsable format. This is particularly useful for users who install applications via methods that don't automatically integrate with the system's default application list, such as AppImages, portable binaries, or user-compiled software. By manually adding a .desktop file to ~/.local/share/applications/, a user can then use xdgctl to seamlessly integrate it into their desktop workflow without ever leaving the terminal.

The project is built with a focus on simplicity and directness. It uses the GLib/GIO libraries, which are the same libraries that power much of the GNOME desktop and provide the backend for many XDG operations. This ensures compatibility and correct behavior. The termbox2 library provides a cross-platform terminal interface, making the tool lightweight and suitable for server environments or minimal desktop setups where a full GUI might not be available or desired.

For users interested in the underlying mechanics, the tool's source code is available on GitHub at mitjafelicijan/xdgctl. The repository includes build instructions for systems like Void Linux, requiring development libraries such as glib-2.0, gio-2.0, and gio-unix-2.0. The installation process follows standard make conventions, allowing for system-wide installation or user-local installation in ~/.local/.

While xdgctl simplifies the interface, understanding the XDG system itself remains valuable. The standard defines several key locations for application data:

  • /usr/share/applications/: System-wide applications.
  • ~/.local/share/applications/: User-specific applications.

The central configuration file is ~/.config/mimeapps.list, which maps MIME types and URI schemes to desktop entries. xdgctl essentially provides a user-friendly editor for this file and the associated desktop entries. For those who prefer manual control, the tool also serves as a helpful reference, showing the correct desktop file names and categories for installed applications.

The project fills a niche for terminal-centric users who still want the conveniences of a modern desktop. It avoids the hype of "revolutionary" tools and instead offers a practical, focused utility that solves a real, everyday problem for Linux users. By providing a clear, navigable interface, xdgctl reduces the cognitive load associated with application management, allowing users to focus on their work rather than on system configuration.

For further reading on the XDG MIME applications specification, the Arch Linux Wiki provides an excellent overview, and the official GLib/GIO documentation details the library functions that tools like xdgctl are built upon. The tool itself is a testament to the power of the terminal and the importance of well-designed interfaces, even for system-level tasks.

Comments

Loading comments...