Nautilus and Nemo use two different icons for python files:
But I want them to show the python icon for all python files.
mimetype gives the same result for both files:
$ mimetype *.py
buy_test.py: text/x-python
candlestick_test.py: text/x-python
file -i gives different outputs:
$ file -i buy_test.py
buy_test.py: text/x-python; charset=us-ascii
$ file -i candlestick_test.py
candlestick_test.py: text/x-objective-c; charset=us-ascii
The output for candlestick_test.py is wrong but this file is shown with the python icon. No idea why.
Somebody here had the same problem: Ubuntu file manager is not showing proper icons
But the answer he got, doesn't work for me:
$ grep -r 'text/x-python' /usr/share/thumbnailers
No output.
I think the main diffenrence between these python files is the shebang:
$ head -n2 buy_test.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
$ head -n2 candlestick_test.py
# -*- coding: utf-8 -*-
"""
When I use this shebang (python 2) ...
#!/usr/bin/env python
... there is a python icon, too.
How do Nautilus and Nemo choose file icons?
EDIT:
Some additional information:
There is a python icon if I use one of these shebangs:
#!/usr/bin/env python
#!/usr/bin/python
There is no python icon if I use one of these shebangs:
#!/usr/bin/env python3
#!/usr/bin/python3
So it looks like python3 is a problem.
EDIT 2:
xdg-mime query filetype FILENAME returns the MIME type matching the shebang:
$ xdg-mime query filetype buy_test.py
text/x-python3
$ xdg-mime query filetype candlestick_test.py
text/x-python
And when I change candlestick_test.py's file extension to .py3, the python icon disappears and xdg-mime query filetype returns text/x-python3.
EDIT 3:
I found a new source of information:
$ gio info ~/python/buy_test.py | grep icon
standard::icon: text-x-python3, text-x-generic
standard::symbolic-icon: text-x-python3-symbolic, text-x-generic-symbolic, text-x-python3, text-x-generic
$ gio info ~/python/candlestick_test.py | grep icon
standard::icon: text-x-python, text-x-generic
standard::symbolic-icon: text-x-python-symbolic, text-x-generic-symbolic, text-x-python, text-x-generic
So I guess, I have to link text-x-python3 files to text-x-python icons somehow.