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.
Finally I could fix it!
As far as I understand, Nemo and Nautilus try to load a file named text-x-python3.svg from /usr/share/icons/[MyTheme]/mimes/[ActualIconSize]/. If there is such a file in ~/.local/share/icons/[MyTheme]/mimes/[ActualIconSize]/ it has a higher priority. But none of these directories existed for my theme: Humanity-Dark.
So Nemo/Nautilus try to find that icon in another theme. In /usr/share/icons/Humanity-Dark/index.theme is defined which theme to try next:
Next try is Humanity. There are icons for text-x-python but not for text-x-python3. So I did:
Same for icon sizes 16 and 22. Now it looks as expected:
Maybe this solution is helpful for someone else.
I had a nearly identical problem in Thunar. I had a slightly different solution. I'm using the elementary Xfce icon theme, so change the commands below as appropriate:
The last command to refresh the icon cache was necessary for me to see the changes in Thunar. After running the commands above I simply refreshed the directory in Thunar and everything was working as expected.