aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2026-01-15-change-default-applications-on-linux.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2026-01-15-change-default-applications-on-linux.md')
-rw-r--r--content/posts/2026-01-15-change-default-applications-on-linux.md101
1 files changed, 101 insertions, 0 deletions
diff --git a/content/posts/2026-01-15-change-default-applications-on-linux.md b/content/posts/2026-01-15-change-default-applications-on-linux.md
new file mode 100644
index 0000000..9e5990a
--- /dev/null
+++ b/content/posts/2026-01-15-change-default-applications-on-linux.md
@@ -0,0 +1,101 @@
1---
2title: Change default applications on Linux from terminal
3url: change-default-applications-on-linux-from-terminal.html
4date: 2026-01-15T16:13:13+02:00
5type: post
6draft: false
7tags: []
8---
9
10Changing default applications is done with command `xdg-mime`. This is a
11command line tool for querying information about file type handling and adding
12descriptions for new file types. Make sure you have this program installed.
13
14Application will use `.desktop` files to associate applications with specific
15types.
16
17## Location and structure of `.desktop` files
18
19```sh
20ls /usr/share/applications
21ls ~/.local/share/applications
22```
23
24You can add your own `.desktop` files to `~/.local/share/applications`.
25
26An example of `.desktop` file for Brave browser located in
27`~/.local/share/applications/brave.desktop`.
28
29```ini
30[Desktop Entry]
31Exec=/home/m/Applications/brave
32Type=Application
33Categories=Applications
34Name=Brave Browser
35```
36
37## Query current associations
38
39You can query specific types with `xdg-mime`.
40
41```sh
42xdg-mime query default text/plain
43xdg-mime query default text/html
44xdg-mime query default x-scheme-handler/http
45xdg-mime query default x-scheme-handler/https
46xdg-mime query default inode/directory
47```
48
49Or you can look at the files containing this data.
50
51```sh
52less ~/.config/mimeapps.list
53less /usr/share/applications/mimeapps.list
54```
55
56## Set default application
57
58```sh
59# Set Brave as default browser.
60xdg-mime default brave.desktop x-scheme-handler/http
61xdg-mime default brave.desktop x-scheme-handler/https
62
63# Set Thunar as default file explorer.
64xdg-mime default thunar.desktop inode/directory
65
66# Set Mousepad as default txt editor.
67xdg-mime default mousepad.desktop text/plain
68```
69
70## Interfacing with C
71
72This simple example lists all registered types. But you can see where this can
73go. This could be turned into ncurses CLI application that is used for setting
74and changing default applications.
75
76```c
77#include <gio/gio.h>
78
79int main(void) {
80 GList *types = g_content_types_get_registered();
81
82 for (GList *l=types; l!=NULL; l=l->next) {
83 g_print("%s\n", (char *)l->data);
84 }
85
86 g_list_free_full(types, g_free);
87 return 0;
88}
89```
90
91Compile with `clang -o main main.c $(pkg-config --cflags --libs gio-2.0)`.
92
93## Reading material
94
95- https://wiki.archlinux.org/title/XDG_MIME_Applications
96- https://commandmasters.com/commands/xdg-mime-linux/
97- https://noman.sh/en/pages/xdg-mime
98- https://linux.die.net/man/1/xdg-mime
99- https://wiki.archlinux.org/title/XDG_MIME_Applications
100- https://gnome.pages.gitlab.gnome.org/libsoup/gio/
101- https://docs.gtk.org/gio/