Krolyxon
Commit 25f893c

Branches

Refs →

dotfiles-x11.configrangerpluginsranger_deviconsdevicons.py

381 lines · 12.5 KB · Python

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