From 9639e64ffe32340afe69ffc45497d7e95db10fe9 Mon Sep 17 00:00:00 2001 From: dbroqua Date: Sat, 31 Oct 2020 15:49:06 +0100 Subject: [PATCH] Added ranger file browser --- config/ranger/plugins/__init__.py | 19 + .../__pycache__/__init__.cpython-37.opt-1.pyc | Bin 0 -> 996 bytes .../__pycache__/compress.cpython-37.opt-1.pyc | Bin 0 -> 1881 bytes .../__pycache__/devicons.cpython-37.opt-1.pyc | Bin 0 -> 5206 bytes .../__pycache__/extract.cpython-37.opt-1.pyc | Bin 0 -> 2661 bytes config/ranger/plugins/compress.py | 43 +++ config/ranger/plugins/devicons.py | 363 ++++++++++++++++++ config/ranger/plugins/extract.py | 81 ++++ config/ranger/rc.conf | 3 + 9 files changed, 509 insertions(+) create mode 100644 config/ranger/plugins/__init__.py create mode 100644 config/ranger/plugins/__pycache__/__init__.cpython-37.opt-1.pyc create mode 100644 config/ranger/plugins/__pycache__/compress.cpython-37.opt-1.pyc create mode 100644 config/ranger/plugins/__pycache__/devicons.cpython-37.opt-1.pyc create mode 100644 config/ranger/plugins/__pycache__/extract.cpython-37.opt-1.pyc create mode 100644 config/ranger/plugins/compress.py create mode 100644 config/ranger/plugins/devicons.py create mode 100644 config/ranger/plugins/extract.py create mode 100644 config/ranger/rc.conf diff --git a/config/ranger/plugins/__init__.py b/config/ranger/plugins/__init__.py new file mode 100644 index 0000000..aeca62b --- /dev/null +++ b/config/ranger/plugins/__init__.py @@ -0,0 +1,19 @@ +import ranger.api +from ranger.core.linemode import LinemodeBase +from .devicons import * + +@ranger.api.register_linemode +class DevIconsLinemode(LinemodeBase): + name = "devicons" + + uses_metadata = False + + def filetitle(self, file, metadata): + return devicon(file) + ' ' + file.relative_path + +@ranger.api.register_linemode +class DevIconsLinemodeFile(LinemodeBase): + name = "filename" + + def filetitle(self, file, metadata): + return devicon(file) + ' ' + file.relative_path diff --git a/config/ranger/plugins/__pycache__/__init__.cpython-37.opt-1.pyc b/config/ranger/plugins/__pycache__/__init__.cpython-37.opt-1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4e518679ea59673419113d262f349af5933dbb3f GIT binary patch literal 996 zcmb7D!H&}~5VhkZbxQ+XSOh`{aSexr4?t+OphZZiS_w|MSfO^iuH3ZPX(bT1?q~1= z{E{ymIPEX&iJ3I1%4#{_$ZsZNd;I22a+)Lq0wX*BA%0Ope&b6wB5+P%x^nL=>Gz^Y|T+k&G{ij1}9mEiHQccu#VO^ES>U{YcXO6=Wsjl=|TZ zU8%)Vs?*Y`D_}t&NMB5Fy&C~ICotVp0M+m)0!a%dgCay8m!ybf1bJgWdaE|?C(Fup zc|DhEqcL(eVQ?M?T1@%|rn?VNlkap(C4B^T4hX4&@il#(2ENxG_lZ@eto25TRasx8 z%!f{ysSl^xD9;zFE@fGlKZ#8s;q}Y>V!2Sc{A`zB)@7anfvKM5wyb8#<}0(F>B{9o z=t|c@WUH^fkBMqs8+8Y1AwNRDJ-Jy=w%;~}a=8#yxlls*fe;|$+Mqua0xmV}N{H4c zYp0y(Xxe*_y4f_ZE0XR7~4mmS^R=63TB50sQnI_Vz5f=Z>Q$7+xQ$R8rczMI6}aK_5s2_#d-*< zc##VMP%Mj)wC@MIMrY+p`*`R3<2E)~T9ujhv$xo1i&}ezn~$uTX;&*N_B*f}P2Pj* bnmX}j&tL7@{u=)shazw~q&yf=&PVhQ#Bbiy literal 0 HcmV?d00001 diff --git a/config/ranger/plugins/__pycache__/compress.cpython-37.opt-1.pyc b/config/ranger/plugins/__pycache__/compress.cpython-37.opt-1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5af4c583b7fd6e97f6d29bdb0b6df3596c9d7b09 GIT binary patch literal 1881 zcmZ`)&u`;I6rLY;;LDy5>myuw`vR)&!Ou*7$g}|L556F!7j*<3oaa(!9V&mUR+G3N@^WbFviw_ z4mT$py8a7>D>f!$`i@+Y1zVCit*PF{8(q>%He!Mae&Nm86&dq)6l|S^yCjPiSn{%6 z^K&YkQ%C(E+=W*|Y(alwACe_a=-k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hy6FaQ zEc=>OU$M@ceOfwOgs<~6N2FwT$YU5?y5P^*=f<>F)@En;Mrq8!H@)ZC*+yBLQ`i-g zvN?&qssiap*(es=@5PD8{UY%^?6`4HrGr4Mb{^H3;B8q!BGfw>wR?%7Y zlQ`DD)9vxMIL~_ zU2zcSMUd@J*!AzAh`W>eBGz%*zv)l5R;@+Udoml|^pz8i(@_}hzY?|kuz0=!rcX-p z&_itx$WQE%d7sESbi=MDo*jb0+BX#K>E6mT;QLGORsudjjz+hy;aZpun@ld9dbZVg z$c7opey%Jo@<=LEijXTS>=i<`Hl+nCDW}+rb4XQ{Gl)M3C(crd*;Xb>LRtAJi3`QD zT$zI`PL(?h_XW(!)fy=9FxVaUdO|8IN<=7?2cbUhG7_37%O-ZYSt@k9TSEr}JY%=H2naZj(oA~f@{hm}%cU+esmYoq)Tqris7YU^O{mwIM?F@D z?{#_(`Wf}1Hd+5$E_MKRZV=!}gFtyfFwFQk!FoLiK+s9`MRs7f6X`}dNOVe~f-yTf z*)G-X2-?dBMX(L!pKyEZRZwIYkbEgk4C@lRzd=JoMqlOudqx1h#sa=?zY5>#S7T}d zgl&YZo~ywN5OA;+*oC8^=mHc+yjHjaHmjA^fN22Q07Y-v=T&_NUn2$|Zcm+JjjsV7 z&C(eFSOJUh?&I6$b>09xx}`g-^X3UWHfGJzMLa%w`fY{C^~qI#aZ_JmWa#JPU5JMU zWDMN=zogUmM`9qQ1E$5Ki*<}H)K@ZFr4_~d8I%>Ft}K*uoTK(>q*^8qGmpU1T)|B^ z?d#M5f7uQ&>&`;x0OC|$hXE%PrWNnu?G5zp_#8ejoU!TT+P^xpnyJZoSFXbX{}GWA zA^4zW$Sw24mvah($?SPD|Pw< 1: + au_flags = [' '.join(parts[1:])] + else: + au_flags = [os.path.basename(self.fm.thisdir.path) + '.zip'] + + # Making description line + files_num = len(marked_files) + files_num_str = str(files_num) + ' objects' if files_num > 1 else '1 object' + descr = "Compressing " + files_num_str + " -> " + os.path.basename(au_flags[0]) + + # Creating archive + obj = CommandLoader(args=['apack'] + au_flags + \ + [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr, read=True) + + obj.signal_bind('after', refresh) + self.fm.loader.add(obj) + + def tab(self, tabnum): + """ Complete with current folder name """ + + extension = ['.zip', '.tar.gz', '.rar', '.7z'] + return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension] diff --git a/config/ranger/plugins/devicons.py b/config/ranger/plugins/devicons.py new file mode 100644 index 0000000..bdfaa86 --- /dev/null +++ b/config/ranger/plugins/devicons.py @@ -0,0 +1,363 @@ +#!/usr/bin/python +# coding=UTF-8 +# These glyphs, and the mapping of file extensions to glyphs +# has been copied from the vimscript code that is present in +# https://github.com/ryanoasis/vim-devicons +import re; +import os; + +# all those glyphs will show as weird squares if you don't have the correct patched font +# My advice is to use NerdFonts which can be found here: +# https://github.com/ryanoasis/nerd-fonts +file_node_extensions = { + '7z' : '', + 'a' : '', + 'ai' : '', + 'apk' : '', + 'asm' : '', + 'asp' : '', + 'aup' : '', + 'avi' : '', + 'awk' : '', + 'bash' : '', + 'bat' : '', + 'bmp' : '', + 'bz2' : '', + 'c' : '', + 'c++' : '', + 'cab' : '', + 'cbr' : '', + 'cbz' : '', + 'cc' : '', + 'class' : '', + 'clj' : '', + 'cljc' : '', + 'cljs' : '', + 'cmake' : '', + 'coffee' : '', + 'conf' : '', + 'cp' : '', + 'cpio' : '', + 'cpp' : '', + 'cs' : '', + 'csh' : '', + 'css' : '', + 'cue' : '', + 'cvs' : '', + 'cxx' : '', + 'd' : '', + 'dart' : '', + 'db' : '', + 'deb' : '', + 'diff' : '', + 'dll' : '', + 'doc' : '', + 'docx' : '', + 'dump' : '', + 'edn' : '', + 'eex' : '', + 'efi' : '', + 'ejs' : '', + 'elf' : '', + 'elm' : '', + 'epub' : '', + 'erl' : '', + 'ex' : '', + 'exe' : '', + 'exs' : '', + 'f#' : '', + 'fifo' : '|', + 'fish' : '', + 'flac' : '', + 'flv' : '', + 'fs' : '', + 'fsi' : '', + 'fsscript' : '', + 'fsx' : '', + 'gem' : '', + 'gemspec' : '', + 'gif' : '', + 'go' : '', + 'gz' : '', + 'gzip' : '', + 'h' : '', + 'haml' : '', + 'hbs' : '', + 'hh' : '', + 'hpp' : '', + 'hrl' : '', + 'hs' : '', + 'htaccess' : '', + 'htm' : '', + 'html' : '', + 'htpasswd' : '', + 'hxx' : '', + 'ico' : '', + 'img' : '', + 'ini' : '', + 'iso' : '', + 'jar' : '', + 'java' : '', + 'jl' : '', + 'jpeg' : '', + 'jpg' : '', + 'js' : '', + 'json' : '', + 'jsx' : '', + 'key' : '', + 'ksh' : '', + 'leex' : '', + 'less' : '', + 'lha' : '', + 'lhs' : '', + 'log' : '', + 'lua' : '', + 'lzh' : '', + 'lzma' : '', + 'm4a' : '', + 'm4v' : '', + 'markdown' : '', + 'md' : '', + 'mdx' : '', + 'mjs' : '', + 'mkv' : '', + 'ml' : 'λ', + 'mli' : 'λ', + 'mov' : '', + 'mp3' : '', + 'mp4' : '', + 'mpeg' : '', + 'mpg' : '', + 'msi' : '', + 'mustache' : '', + 'nix' : '', + 'o' : '', + 'ogg' : '', + 'pdf' : '', + 'php' : '', + 'pl' : '', + 'pm' : '', + 'png' : '', + 'pp' : '', + 'ppt' : '', + 'pptx' : '', + 'ps1' : '', + 'psb' : '', + 'psd' : '', + 'pub' : '', + 'py' : '', + 'pyc' : '', + 'pyd' : '', + 'pyo' : '', + 'r' : 'ﳒ', + 'rake' : '', + 'rar' : '', + 'rb' : '', + 'rc' : '', + 'rlib' : '', + 'rmd' : '', + 'rom' : '', + 'rpm' : '', + 'rproj' : '鉶', + 'rs' : '', + 'rss' : '', + 'rtf' : '', + 's' : '', + 'sass' : '', + 'scala' : '', + 'scss' : '', + 'sh' : '', + 'slim' : '', + 'sln' : '', + 'so' : '', + 'sql' : '', + 'styl' : '', + 'suo' : '', + 'swift' : '', + 't' : '', + 'tar' : '', + 'tex' : 'ﭨ', + 'tgz' : '', + 'toml' : '', + 'ts' : '', + 'tsx' : '', + 'twig' : '', + 'vim' : '', + 'vimrc' : '', + 'vue' : '﵂', + 'wav' : '', + 'webm' : '', + 'webmanifest' : '', + 'webp' : '', + 'xbps' : '', + 'xcplayground' : '', + 'xhtml' : '', + 'xls' : '', + 'xlsx' : '', + 'xml' : '', + 'xul' : '', + 'xz' : '', + 'yaml' : '', + 'yml' : '', + 'zip' : '', + 'zsh' : '', +} + +dir_node_exact_matches = { +# English + '.git' : '', + 'Desktop' : '', + 'Documents' : '', + 'Downloads' : '', + 'Dotfiles' : '', + 'Dropbox' : '', + 'Music' : '', + 'Pictures' : '', + 'Public' : '', + 'Templates' : '', + 'Videos' : '', +# Spanish + 'Escritorio' : '', + 'Documentos' : '', + 'Descargas' : '', + 'Música' : '', + 'Imágenes' : '', + 'Público' : '', + 'Plantillas' : '', + 'Vídeos' : '', +# French + 'Bureau' : '', + 'Documents' : '', + 'Images' : '', + 'Musique' : '', + 'Publique' : '', + 'Téléchargements' : '', + 'Vidéos' : '', +# Portuguese + 'Documentos' : '', + 'Imagens' : '', + 'Modelos' : '', + 'Música' : '', + 'Público' : '', + 'Vídeos' : '', + 'Área de trabalho' : '', +# Italian + 'Documenti' : '', + 'Immagini' : '', + 'Modelli' : '', + 'Musica' : '', + 'Pubblici' : '', + 'Scaricati' : '', + 'Scrivania' : '', + 'Video' : '', +# German + 'Bilder' : '', + 'Dokumente' : '', + 'Musik' : '', + 'Schreibtisch' : '', + 'Vorlagen' : '', + 'Öffentlich' : '', +# Hungarian + 'Dokumentumok' : '', + 'Képek' : '', + 'Modelli' : '', + 'Zene' : '', + 'Letöltések' : '', + 'Számítógép' : '', + 'Videók' : '', +} + +file_node_exact_matches = { + '.bash_aliases' : '', + '.bash_history' : '', + '.bash_logout' : '', + '.bash_profile' : '', + '.bashprofile' : '', + '.bashrc' : '', + '.dmrc' : '', + '.DS_Store' : '', + '.fasd' : '', + '.fehbg' : '', + '.gitattributes' : '', + '.gitconfig' : '', + '.gitignore' : '', + '.gitlab-ci.yml' : '', + '.gvimrc' : '', + '.inputrc' : '', + '.jack-settings' : '', + '.mime.types' : '', + '.ncmpcpp' : '', + '.nvidia-settings-rc' : '', + '.pam_environment' : '', + '.profile' : '', + '.recently-used' : '', + '.selected_editor' : '', + '.vim' : '', + '.viminfo' : '', + '.vimrc' : '', + '.Xauthority' : '', + '.Xdefaults' : '', + '.xinitrc' : '', + '.xinputrc' : '', + '.Xresources' : '', + '.zshrc' : '', + '_gvimrc' : '', + '_vimrc' : '', + 'a.out' : '', + 'authorized_keys' : '', + 'bspwmrc' : '', + 'cmakelists.txt' : '', + 'config' : '', + 'config.ac' : '', + 'config.m4' : '', + 'config.mk' : '', + 'config.ru' : '', + 'configure' : '', + 'docker-compose.yml' : '', + 'dockerfile' : '', + 'Dockerfile' : '', + 'dropbox' : '', + 'exact-match-case-sensitive-1.txt' : 'X1', + 'exact-match-case-sensitive-2' : 'X2', + 'favicon.ico' : '', + 'gemfile' : '', + 'gruntfile.coffee' : '', + 'gruntfile.js' : '', + 'gruntfile.ls' : '', + 'gulpfile.coffee' : '', + 'gulpfile.js' : '', + 'gulpfile.ls' : '', + 'ini' : '', + 'known_hosts' : '', + 'ledger' : '', + 'license' : '', + 'LICENSE' : '', + 'LICENSE.md' : '', + 'LICENSE.txt' : '', + 'Makefile' : '', + 'makefile' : '', + 'Makefile.ac' : '', + 'Makefile.in' : '', + 'mimeapps.list' : '', + 'mix.lock' : '', + 'node_modules' : '', + 'package-lock.json' : '', + 'package.json' : '', + 'playlists' : '', + 'procfile' : '', + 'Rakefile' : '', + 'rakefile' : '', + 'react.jsx' : '', + 'README' : '', + 'README.markdown' : '', + 'README.md' : '', + 'README.rst' : '', + 'README.txt' : '', + 'sxhkdrc' : '', + 'user-dirs.dirs' : '', + 'webpack.config.js' : '', +} + +def devicon(file): + if file.is_directory: return dir_node_exact_matches.get(file.relative_path, '') + return file_node_exact_matches.get(os.path.basename(file.relative_path), file_node_extensions.get(file.extension, '')) diff --git a/config/ranger/plugins/extract.py b/config/ranger/plugins/extract.py new file mode 100644 index 0000000..9585274 --- /dev/null +++ b/config/ranger/plugins/extract.py @@ -0,0 +1,81 @@ +import os +from ranger.api.commands import * +from ranger.core.loader import CommandLoader + +class extract(Command): + def execute(self): + """Extract copied files to current directory or directory + specified in a command line + """ + + cwd = self.fm.thisdir + copied_files = cwd.get_selection() + + if not copied_files: + return + + def refresh(_): + cwd = self.fm.get_directory(original_path) + cwd.load_content() + + one_file = copied_files[0] + cwd = self.fm.thisdir + original_path = cwd.path + + line_args = self.line.split()[1:] + if line_args: + extraction_dir = os.path.join(cwd.path, "".join(line_args)) + os.makedirs(extraction_dir, exist_ok=True) + flags = ['-X', extraction_dir] + flags += ['-e'] + else: + flags = ['-X', cwd.path] + flags += ['-e'] + + self.fm.copy_buffer.clear() + self.fm.cut_buffer = False + + if len(copied_files) == 1: + descr = "Extracting: " + os.path.basename(one_file.path) + else: + descr = "Extracting files from: " + os.path.basename(one_file.dirname) + obj = CommandLoader(args=['aunpack'] + flags \ + + [f.path for f in copied_files], descr=descr, read=True) + + obj.signal_bind('after', refresh) + self.fm.loader.add(obj) + +class extract_to_dirs(Command): + def execute(self): + """ Extract copied files to a subdirectories """ + + cwd = self.fm.thisdir + original_path = cwd.path + copied_files = cwd.get_selection() + + if not copied_files: + return + + def refresh(_): + cwd = self.fm.get_directory(original_path) + cwd.load_content() + + def make_flags(fn): + flags = ['-D'] + return flags + + one_file = copied_files[0] + self.fm.copy_buffer.clear() + self.fm.cut_buffer = False + + # Making description line + if len(copied_files) == 1: + descr = "Extracting: " + os.path.basename(one_file.path) + else: + descr = "Extracting files from: " + os.path.basename(one_file.dirname) + + # Extracting files + for f in copied_files: + obj = CommandLoader(args=['aunpack'] + make_flags(f.path) + [f.path], descr=descr, read=True) + obj.signal_bind('after', refresh) + self.fm.loader.add(obj) diff --git a/config/ranger/rc.conf b/config/ranger/rc.conf new file mode 100644 index 0000000..a2683b2 --- /dev/null +++ b/config/ranger/rc.conf @@ -0,0 +1,3 @@ +default_linemode devicons +set preview_images true +