In linux, how can I determine the default text editor, terminal, etc?
does it vary by distro?
In linux, how can I determine the default text editor, terminal, etc?
does it vary by distro?
Per-user environment variables tells you that.
This however is valid for command line softwares, while usually desktop environments use their own (internal) variables.
Also in python you can read the environment variables using os.getenv
.
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.
This works in ubuntu/gnome:
>>> query_lines = subprocess.check_output(['update-alternatives',
'--query',
'gnome-text-editor']).split('\n')
>>> bestlist = filter(lambda l: 'Best' in l, query_lines)
>>> bestlist[0].split()[1]
'/usr/bin/gedit'
If not on gnome, you could at least get the command-line editor:
>>> query_lines = subprocess.check_output(['update-alternatives',
... '--query',
... 'editor']).split('\n')
>>> bestlist = filter(lambda l: 'Best' in l, query_lines)
>>> bestlist[0].split()[1]
'/bin/nano'
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
.
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