devicons.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. #!/usr/bin/python
  2. # coding=UTF-8
  3. # These glyphs, and the mapping of file extensions to glyphs
  4. # has been copied from the vimscript code that is present in
  5. # https://github.com/ryanoasis/vim-devicons
  6. import re;
  7. import os;
  8. # all those glyphs will show as weird squares if you don't have the correct patched font
  9. # My advice is to use NerdFonts which can be found here:
  10. # https://github.com/ryanoasis/nerd-fonts
  11. file_node_extensions = {
  12. '7z' : '',
  13. 'a' : '',
  14. 'ai' : '',
  15. 'apk' : '',
  16. 'asm' : '',
  17. 'asp' : '',
  18. 'aup' : '',
  19. 'avi' : '',
  20. 'awk' : '',
  21. 'bash' : '',
  22. 'bat' : '',
  23. 'bmp' : '',
  24. 'bz2' : '',
  25. 'c' : '',
  26. 'c++' : '',
  27. 'cab' : '',
  28. 'cbr' : '',
  29. 'cbz' : '',
  30. 'cc' : '',
  31. 'class' : '',
  32. 'clj' : '',
  33. 'cljc' : '',
  34. 'cljs' : '',
  35. 'cmake' : '',
  36. 'coffee' : '',
  37. 'conf' : '',
  38. 'cp' : '',
  39. 'cpio' : '',
  40. 'cpp' : '',
  41. 'cs' : '',
  42. 'csh' : '',
  43. 'css' : '',
  44. 'cue' : '',
  45. 'cvs' : '',
  46. 'cxx' : '',
  47. 'd' : '',
  48. 'dart' : '',
  49. 'db' : '',
  50. 'deb' : '',
  51. 'diff' : '',
  52. 'dll' : '',
  53. 'doc' : '',
  54. 'docx' : '',
  55. 'dump' : '',
  56. 'edn' : '',
  57. 'eex' : '',
  58. 'efi' : '',
  59. 'ejs' : '',
  60. 'elf' : '',
  61. 'elm' : '',
  62. 'epub' : '',
  63. 'erl' : '',
  64. 'ex' : '',
  65. 'exe' : '',
  66. 'exs' : '',
  67. 'f#' : '',
  68. 'fifo' : '|',
  69. 'fish' : '',
  70. 'flac' : '',
  71. 'flv' : '',
  72. 'fs' : '',
  73. 'fsi' : '',
  74. 'fsscript' : '',
  75. 'fsx' : '',
  76. 'gem' : '',
  77. 'gemspec' : '',
  78. 'gif' : '',
  79. 'go' : '',
  80. 'gz' : '',
  81. 'gzip' : '',
  82. 'h' : '',
  83. 'haml' : '',
  84. 'hbs' : '',
  85. 'hh' : '',
  86. 'hpp' : '',
  87. 'hrl' : '',
  88. 'hs' : '',
  89. 'htaccess' : '',
  90. 'htm' : '',
  91. 'html' : '',
  92. 'htpasswd' : '',
  93. 'hxx' : '',
  94. 'ico' : '',
  95. 'img' : '',
  96. 'ini' : '',
  97. 'iso' : '',
  98. 'jar' : '',
  99. 'java' : '',
  100. 'jl' : '',
  101. 'jpeg' : '',
  102. 'jpg' : '',
  103. 'js' : '',
  104. 'json' : '',
  105. 'jsx' : '',
  106. 'key' : '',
  107. 'ksh' : '',
  108. 'leex' : '',
  109. 'less' : '',
  110. 'lha' : '',
  111. 'lhs' : '',
  112. 'log' : '',
  113. 'lua' : '',
  114. 'lzh' : '',
  115. 'lzma' : '',
  116. 'm4a' : '',
  117. 'm4v' : '',
  118. 'markdown' : '',
  119. 'md' : '',
  120. 'mdx' : '',
  121. 'mjs' : '',
  122. 'mkv' : '',
  123. 'ml' : 'λ',
  124. 'mli' : 'λ',
  125. 'mov' : '',
  126. 'mp3' : '',
  127. 'mp4' : '',
  128. 'mpeg' : '',
  129. 'mpg' : '',
  130. 'msi' : '',
  131. 'mustache' : '',
  132. 'nix' : '',
  133. 'o' : '',
  134. 'ogg' : '',
  135. 'pdf' : '',
  136. 'php' : '',
  137. 'pl' : '',
  138. 'pm' : '',
  139. 'png' : '',
  140. 'pp' : '',
  141. 'ppt' : '',
  142. 'pptx' : '',
  143. 'ps1' : '',
  144. 'psb' : '',
  145. 'psd' : '',
  146. 'pub' : '',
  147. 'py' : '',
  148. 'pyc' : '',
  149. 'pyd' : '',
  150. 'pyo' : '',
  151. 'r' : 'ﳒ',
  152. 'rake' : '',
  153. 'rar' : '',
  154. 'rb' : '',
  155. 'rc' : '',
  156. 'rlib' : '',
  157. 'rmd' : '',
  158. 'rom' : '',
  159. 'rpm' : '',
  160. 'rproj' : '鉶',
  161. 'rs' : '',
  162. 'rss' : '',
  163. 'rtf' : '',
  164. 's' : '',
  165. 'sass' : '',
  166. 'scala' : '',
  167. 'scss' : '',
  168. 'sh' : '',
  169. 'slim' : '',
  170. 'sln' : '',
  171. 'so' : '',
  172. 'sql' : '',
  173. 'styl' : '',
  174. 'suo' : '',
  175. 'swift' : '',
  176. 't' : '',
  177. 'tar' : '',
  178. 'tex' : 'ﭨ',
  179. 'tgz' : '',
  180. 'toml' : '',
  181. 'ts' : '',
  182. 'tsx' : '',
  183. 'twig' : '',
  184. 'vim' : '',
  185. 'vimrc' : '',
  186. 'vue' : '﵂',
  187. 'wav' : '',
  188. 'webm' : '',
  189. 'webmanifest' : '',
  190. 'webp' : '',
  191. 'xbps' : '',
  192. 'xcplayground' : '',
  193. 'xhtml' : '',
  194. 'xls' : '',
  195. 'xlsx' : '',
  196. 'xml' : '',
  197. 'xul' : '',
  198. 'xz' : '',
  199. 'yaml' : '',
  200. 'yml' : '',
  201. 'zip' : '',
  202. 'zsh' : '',
  203. }
  204. dir_node_exact_matches = {
  205. # English
  206. '.git' : '',
  207. 'Desktop' : '',
  208. 'Documents' : '',
  209. 'Downloads' : '',
  210. 'Dotfiles' : '',
  211. 'Dropbox' : '',
  212. 'Music' : '',
  213. 'Pictures' : '',
  214. 'Public' : '',
  215. 'Templates' : '',
  216. 'Videos' : '',
  217. # Spanish
  218. 'Escritorio' : '',
  219. 'Documentos' : '',
  220. 'Descargas' : '',
  221. 'Música' : '',
  222. 'Imágenes' : '',
  223. 'Público' : '',
  224. 'Plantillas' : '',
  225. 'Vídeos' : '',
  226. # French
  227. 'Bureau' : '',
  228. 'Documents' : '',
  229. 'Images' : '',
  230. 'Musique' : '',
  231. 'Publique' : '',
  232. 'Téléchargements' : '',
  233. 'Vidéos' : '',
  234. # Portuguese
  235. 'Documentos' : '',
  236. 'Imagens' : '',
  237. 'Modelos' : '',
  238. 'Música' : '',
  239. 'Público' : '',
  240. 'Vídeos' : '',
  241. 'Área de trabalho' : '',
  242. # Italian
  243. 'Documenti' : '',
  244. 'Immagini' : '',
  245. 'Modelli' : '',
  246. 'Musica' : '',
  247. 'Pubblici' : '',
  248. 'Scaricati' : '',
  249. 'Scrivania' : '',
  250. 'Video' : '',
  251. # German
  252. 'Bilder' : '',
  253. 'Dokumente' : '',
  254. 'Musik' : '',
  255. 'Schreibtisch' : '',
  256. 'Vorlagen' : '',
  257. 'Öffentlich' : '',
  258. # Hungarian
  259. 'Dokumentumok' : '',
  260. 'Képek' : '',
  261. 'Modelli' : '',
  262. 'Zene' : '',
  263. 'Letöltések' : '',
  264. 'Számítógép' : '',
  265. 'Videók' : '',
  266. }
  267. file_node_exact_matches = {
  268. '.bash_aliases' : '',
  269. '.bash_history' : '',
  270. '.bash_logout' : '',
  271. '.bash_profile' : '',
  272. '.bashprofile' : '',
  273. '.bashrc' : '',
  274. '.dmrc' : '',
  275. '.DS_Store' : '',
  276. '.fasd' : '',
  277. '.fehbg' : '',
  278. '.gitattributes' : '',
  279. '.gitconfig' : '',
  280. '.gitignore' : '',
  281. '.gitlab-ci.yml' : '',
  282. '.gvimrc' : '',
  283. '.inputrc' : '',
  284. '.jack-settings' : '',
  285. '.mime.types' : '',
  286. '.ncmpcpp' : '',
  287. '.nvidia-settings-rc' : '',
  288. '.pam_environment' : '',
  289. '.profile' : '',
  290. '.recently-used' : '',
  291. '.selected_editor' : '',
  292. '.vim' : '',
  293. '.viminfo' : '',
  294. '.vimrc' : '',
  295. '.Xauthority' : '',
  296. '.Xdefaults' : '',
  297. '.xinitrc' : '',
  298. '.xinputrc' : '',
  299. '.Xresources' : '',
  300. '.zshrc' : '',
  301. '_gvimrc' : '',
  302. '_vimrc' : '',
  303. 'a.out' : '',
  304. 'authorized_keys' : '',
  305. 'bspwmrc' : '',
  306. 'cmakelists.txt' : '',
  307. 'config' : '',
  308. 'config.ac' : '',
  309. 'config.m4' : '',
  310. 'config.mk' : '',
  311. 'config.ru' : '',
  312. 'configure' : '',
  313. 'docker-compose.yml' : '',
  314. 'dockerfile' : '',
  315. 'Dockerfile' : '',
  316. 'dropbox' : '',
  317. 'exact-match-case-sensitive-1.txt' : 'X1',
  318. 'exact-match-case-sensitive-2' : 'X2',
  319. 'favicon.ico' : '',
  320. 'gemfile' : '',
  321. 'gruntfile.coffee' : '',
  322. 'gruntfile.js' : '',
  323. 'gruntfile.ls' : '',
  324. 'gulpfile.coffee' : '',
  325. 'gulpfile.js' : '',
  326. 'gulpfile.ls' : '',
  327. 'ini' : '',
  328. 'known_hosts' : '',
  329. 'ledger' : '',
  330. 'license' : '',
  331. 'LICENSE' : '',
  332. 'LICENSE.md' : '',
  333. 'LICENSE.txt' : '',
  334. 'Makefile' : '',
  335. 'makefile' : '',
  336. 'Makefile.ac' : '',
  337. 'Makefile.in' : '',
  338. 'mimeapps.list' : '',
  339. 'mix.lock' : '',
  340. 'node_modules' : '',
  341. 'package-lock.json' : '',
  342. 'package.json' : '',
  343. 'playlists' : '',
  344. 'procfile' : '',
  345. 'Rakefile' : '',
  346. 'rakefile' : '',
  347. 'react.jsx' : '',
  348. 'README' : '',
  349. 'README.markdown' : '',
  350. 'README.md' : '',
  351. 'README.rst' : '',
  352. 'README.txt' : '',
  353. 'sxhkdrc' : '',
  354. 'user-dirs.dirs' : '',
  355. 'webpack.config.js' : '',
  356. }
  357. def devicon(file):
  358. if file.is_directory: return dir_node_exact_matches.get(file.relative_path, '')
  359. return file_node_exact_matches.get(os.path.basename(file.relative_path), file_node_extensions.get(file.extension, ''))