unicode_icons.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Unicode Icons in Ranger File Manager
  2. #
  3. # How to install?
  4. # https://gist.github.com/marcbelmont/c12d2fd2519a372d3b347f665b37e74a#gistcomment-3240106
  5. from __future__ import absolute_import, division, print_function
  6. from itertools import repeat
  7. import ranger.api
  8. from ranger.core.linemode import LinemodeBase
  9. # https://unicode.org/emoji/charts/full-emoji-list.html
  10. EXTENSIONS = {}
  11. for extensions, icon in [
  12. ('py pyc', '🐍'),
  13. ('yml ini', '⚙ '),
  14. ]:
  15. EXTENSIONS.update(dict(zip(extensions.split(), repeat(icon))))
  16. # https://github.com/ranger/ranger/blob/081e73152a9391211770fab56676d7d974413ae6/ranger/container/fsobject.py
  17. @ranger.api.register_linemode
  18. class MyLinemode(LinemodeBase):
  19. name = "unicode_icons"
  20. def filetitle(self, fobj, metadata):
  21. if fobj.is_directory:
  22. icon = '📂'
  23. elif fobj.extension in EXTENSIONS:
  24. icon = EXTENSIONS[fobj.extension]
  25. elif fobj.is_link:
  26. icon = '🔗'
  27. elif fobj.audio:
  28. icon = '🎵'
  29. elif fobj.container:
  30. icon = '📦'
  31. elif fobj.document:
  32. icon = '📖'
  33. elif fobj.image:
  34. icon = '🖼️ '
  35. elif fobj.video:
  36. icon = '🎞️ '
  37. elif 'Dockerfile' in fobj.relative_path:
  38. icon = '🐋'
  39. else:
  40. icon = '📃'
  41. return (icon + ' ' if icon else '') + fobj.relative_path
  42. def infostring(self, fobj, metadata):
  43. raise NotImplementedError