nautilus-python sets argv[0] to 'thunar'
I'm writing an extension that detects whether it is running in nautilus, nemo, or caja, to import the correct extension module so it works with all three. It does this by checking sys.argv[0], which is 'nemo' or 'caja' in nemo-python and caja-python.
However, in nautilus-python, sys.argv[0] is 'thunar'. here is a link to where in nautilus-python that is explicitly set.
Is there a reason for this? Thunar would seem to be unrelated to nautilus-python. I am not aware of any cross-compatibility in extensions between nautilus and thunar. Below is an example of what my code does, this prints an error and shows that sys.argv is 'thunar' from the perspective of a nautilus-python extension. It has the same behaviour on Python 2 or 3.
from __future__ import print_function, unicode_literals
import sys
import gi
from gi.repository import GObject
if sys.argv[0] == 'nemo':
gi.require_version('Nemo', '3.0')
from gi.repository import Nemo as Nautilus
elif sys.argv[0] == 'caja':
gi.require_version('Caja', '2.0')
from gi.repository import Caja as Nautilus
elif sys.argv[0] == 'nautilus':
gi.require_version('Nautilus', '3.0')
from gi.repository import Nautilus
else:
print(sys.argv)
print(sys.version)
raise RuntimeError("Not running from within nautilus/caja/nemo")
$ nautilus
['thunar']
2.7.15 (default, Jan 10 2019, 23:20:52)
[GCC 8.2.1 20181127]
Traceback (most recent call last):
File "/usr/share/nautilus-python/extensions/git-nautilus-icons.py", line 36, in <module>
raise RuntimeError("Not running from within nautilus/caja/nemo")
RuntimeError: Not running from within nautilus/caja/nemo