You are not logged in.

#1 2022-03-12 17:59:03

bruh-i-use-arch-cow
Member
Registered: 2020-07-01
Posts: 46

[SOLVED] "xdg-open example.cpp" opens in browser insted of text editor

I expect xdg-open to open text files (like txt, c, cpp) in text editor, for example vscode,
but instead it opens them in firefox every time.

I set xdg-mime specifications and enviroment variables correctly (i think) so im lost at what else is there to do.

xdg-mime specifications:

xdg-mime  query default text/plain
vscodium.desktop

Environment variables:

echo $EDITOR $VISUAL
vscodium vscodium

Last edited by bruh-i-use-arch-cow (2022-03-12 19:16:05)

Offline

#2 2022-03-12 18:52:53

bruh-i-use-arch-cow
Member
Registered: 2020-07-01
Posts: 46

Re: [SOLVED] "xdg-open example.cpp" opens in browser insted of text editor

Turns out xdg-mime specifications was wrong.
The best way that i figured out how to set default applications (with command line) is:
1) Check Mime type for a file you want to change default application:

xdg-mime query file type example.txt
inode/x-empty

2) Change default application by file type:

mimelist.list:

[Default Applications]
inode/x-empty=vscodium.desktop

Offline

#3 2022-03-12 18:58:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [SOLVED] "xdg-open example.cpp" opens in browser insted of text editor

Ah, what?  Is that "example.txt" actually a text file, or did you just create it with `touch`?  inode/x-empty is not the mime-type you'd want to use.  If example.txt is an actually text file (and not really an empty inode just created by `touch`) then you should debug why xdg-mime query is giving an incorrect result.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2022-03-12 19:15:24

bruh-i-use-arch-cow
Member
Registered: 2020-07-01
Posts: 46

Re: [SOLVED] "xdg-open example.cpp" opens in browser insted of text editor

Trilby wrote:

Ah, what?  Is that "example.txt" actually a text file, or did you just create it with `touch`?  inode/x-empty is not the mime-type you'd want to use.  If example.txt is an actually text file (and not really an empty inode just created by `touch`) then you should debug why xdg-mime query is giving an incorrect result.

yes, I created example.txt using touch, and yes my xdg-mime is probably broken, but im too lazy to debug it since inode/x-empty approach works.
Better example would probably be with cpp files cause in this case xdg-mime gives me correct results:

xdg-mime query filetype code/minecraft/main.cpp
text/x-c

Offline

#5 2022-03-12 20:37:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [SOLVED] "xdg-open example.cpp" opens in browser insted of text editor

bruh-i-use-arch-cow wrote:

but im too lazy to debug it since inode/x-empty approach works.

Except it will only work with empty files, not real code or text files which is the problem you laid out in the first post.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB