Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically determine default applications in linux

In linux, how can I determine the default text editor, terminal, etc?

does it vary by distro?

like image 417
sqram Avatar asked Jan 06 '12 20:01

sqram


3 Answers

I accessed the list while ago programatically in a rather ugly manner and I'm sure its not the best way. The options are stored in a file called defaults.list (I think this is generally the case). The location is less general I think it in /usr/share/applications/ on my ubuntu system although it does appear elsewhere I think. I then treated it as a text file.

like image 192
Bowler Avatar answered Oct 15 '22 13:10

Bowler


The resolution order is $EDITOR -> editor -> some predefined list of console editors. On Debian/Ubuntu, sensible-editor (and sensible-browser and sensible-pager) will do the lookup for you, including looking at the right environment variables. Similar variables are $PAGER, $SHELL, $BROWSER. To look up a file association, you can use xdg-open.

like image 39
Tobu Avatar answered Oct 15 '22 14:10

Tobu


I don't think that the notion of default editor or terminal makes sense. For the editor, there is the convention of using $EDITOR when it is defined.

On Debian and related (e.g. Ubuntu, Mint) you have paths like /usr/bin/editor and /usr/bin/x-terminal-emulator symlinked (via symlinks in /etc/alternatives/) to some system default.

See also Dacav's answer

like image 1
Basile Starynkevitch Avatar answered Oct 15 '22 15:10

Basile Starynkevitch