ranger: Run formatter on these python files

This commit is contained in:
Sanchayan Maity 2021-04-17 18:22:37 +05:30
parent c8b64ae94f
commit 063af20501
3 changed files with 236 additions and 226 deletions

View file

@ -1,11 +1,13 @@
from ranger.api.commands import Command
class paste_as_root(Command):
def execute(self):
if self.fm.do_cut:
self.fm.execute_console('shell sudo mv %c .')
else:
self.fm.execute_console('shell sudo cp -r %c .')
def execute(self):
if self.fm.do_cut:
self.fm.execute_console("shell sudo mv %c .")
else:
self.fm.execute_console("shell sudo cp -r %c .")
class fzf_select(Command):
"""
@ -17,22 +19,26 @@ class fzf_select(Command):
See: https://github.com/junegunn/fzf
"""
def execute(self):
import subprocess
import os.path
if self.quantifier:
# match only directories
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
command = "find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to file'"
else:
# match files and directories
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
command = "find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to filemap <C-f> fzf_select'"
fzf = self.fm.execute_command(command, universal_newlines=True, stdout=subprocess.PIPE)
fzf = self.fm.execute_command(
command, universal_newlines=True, stdout=subprocess.PIPE
)
stdout, stderr = fzf.communicate()
if fzf.returncode == 0:
fzf_file = os.path.abspath(stdout.rstrip('\n'))
fzf_file = os.path.abspath(stdout.rstrip("\n"))
if os.path.isdir(fzf_file):
self.fm.cd(fzf_file)
else:
self.fm.select_file(fzf_file)
self.fm.select_file(fzf_file)

View file

@ -3,217 +3,220 @@
# 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' : '',
'ai' : '',
'apk' : '',
'avi' : '',
'bat' : '',
'bmp' : '',
'bz2' : '',
'c' : '',
'c++' : '',
'cab' : '',
'cc' : '',
'clj' : '',
'cljc' : '',
'cljs' : '',
'coffee' : '',
'conf' : '',
'cp' : '',
'cpio' : '',
'cpp' : '',
'css' : '',
'cxx' : '',
'd' : '',
'dart' : '',
'db' : '',
'deb' : '',
'diff' : '',
'dump' : '',
'edn' : '',
'ejs' : '',
'epub' : '',
'erl' : '',
'f#' : '',
'fish' : '',
'flac' : '',
'flv' : '',
'fs' : '',
'fsi' : '',
'fsscript' : '',
'fsx' : '',
'gem' : '',
'gif' : '',
'go' : '',
'gz' : '',
'gzip' : '',
'hbs' : '',
'hrl' : '',
'hs' : '',
'htm' : '',
'html' : '',
'ico' : '',
'ini' : '',
'java' : '',
'jl' : '',
'jpeg' : '',
'jpg' : '',
'js' : '',
'json' : '',
'jsx' : '',
'less' : '',
'lha' : '',
'lhs' : '',
'log' : '',
'lua' : '',
'lzh' : '',
'lzma' : '',
'markdown' : '',
'md' : '',
'mkv' : '',
'ml' : 'λ',
'mli' : 'λ',
'mov' : '',
'mp3' : '',
'mp4' : '',
'mpeg' : '',
'mpg' : '',
'mustache' : '',
'ogg' : '',
'pdf' : '',
'php' : '',
'pl' : '',
'pm' : '',
'png' : '',
'psb' : '',
'psd' : '',
'py' : '',
'pyc' : '',
'pyd' : '',
'pyo' : '',
'rar' : '',
'rb' : '',
'rc' : '',
'rlib' : '',
'rpm' : '',
'rs' : '',
'rss' : '',
'scala' : '',
'scss' : '',
'sh' : '',
'slim' : '',
'sln' : '',
'sql' : '',
'styl' : '',
'suo' : '',
't' : '',
'tar' : '',
'tgz' : '',
'ts' : '',
'twig' : '',
'vim' : '',
'vimrc' : '',
'wav' : '',
'xml' : '',
'xul' : '',
'xz' : '',
'yml' : '',
'zip' : '',
"7z": "",
"ai": "",
"apk": "",
"avi": "",
"bat": "",
"bmp": "",
"bz2": "",
"c": "",
"c++": "",
"cab": "",
"cc": "",
"clj": "",
"cljc": "",
"cljs": "",
"coffee": "",
"conf": "",
"cp": "",
"cpio": "",
"cpp": "",
"css": "",
"cxx": "",
"d": "",
"dart": "",
"db": "",
"deb": "",
"diff": "",
"dump": "",
"edn": "",
"ejs": "",
"epub": "",
"erl": "",
"f#": "",
"fish": "",
"flac": "",
"flv": "",
"fs": "",
"fsi": "",
"fsscript": "",
"fsx": "",
"gem": "",
"gif": "",
"go": "",
"gz": "",
"gzip": "",
"hbs": "",
"hrl": "",
"hs": "",
"htm": "",
"html": "",
"ico": "",
"ini": "",
"java": "",
"jl": "",
"jpeg": "",
"jpg": "",
"js": "",
"json": "",
"jsx": "",
"less": "",
"lha": "",
"lhs": "",
"log": "",
"lua": "",
"lzh": "",
"lzma": "",
"markdown": "",
"md": "",
"mkv": "",
"ml": "λ",
"mli": "λ",
"mov": "",
"mp3": "",
"mp4": "",
"mpeg": "",
"mpg": "",
"mustache": "",
"ogg": "",
"pdf": "",
"php": "",
"pl": "",
"pm": "",
"png": "",
"psb": "",
"psd": "",
"py": "",
"pyc": "",
"pyd": "",
"pyo": "",
"rar": "",
"rb": "",
"rc": "",
"rlib": "",
"rpm": "",
"rs": "",
"rss": "",
"scala": "",
"scss": "",
"sh": "",
"slim": "",
"sln": "",
"sql": "",
"styl": "",
"suo": "",
"t": "",
"tar": "",
"tgz": "",
"ts": "",
"twig": "",
"vim": "",
"vimrc": "",
"wav": "",
"xml": "",
"xul": "",
"xz": "",
"yml": "",
"zip": "",
}
dir_node_exact_matches = {
# English
'.git' : '',
'Desktop' : '',
'Documents' : '',
'Downloads' : '',
'Dropbox' : '',
'Music' : '',
'Pictures' : '',
'Public' : '',
'Templates' : '',
'Videos' : '',
# 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' : '',
# English
".git": "",
"Desktop": "",
"Documents": "",
"Downloads": "",
"Dropbox": "",
"Music": "",
"Pictures": "",
"Public": "",
"Templates": "",
"Videos": "",
# 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": "",
}
file_node_exact_matches = {
'.Xdefaults' : '',
'.Xresources' : '',
'.bashprofile' : '',
'.bashrc' : '',
'.dmrc' : '',
'.ds_store' : '',
'.fasd' : '',
'.gitconfig' : '',
'.gitignore' : '',
'.jack-settings' : '',
'.mime.types' : '',
'.nvidia-settings-rc' : '',
'.pam_environment' : '',
'.profile' : '',
'.recently-used' : '',
'.selected_editor' : '',
'.vimrc' : '',
'.xinputrc' : '',
'config' : '',
'dropbox' : '',
'exact-match-case-sensitive-1.txt' : 'X1',
'exact-match-case-sensitive-2' : 'X2',
'favicon.ico' : '',
'gruntfile.coffee' : '',
'gruntfile.js' : '',
'gruntfile.ls' : '',
'gulpfile.coffee' : '',
'gulpfile.js' : '',
'gulpfile.ls' : '',
'ini' : '',
'ledger' : '',
'license' : '',
'mimeapps.list' : '',
'node_modules' : '',
'procfile' : '',
'react.jsx' : '',
'user-dirs.dirs' : '',
".Xdefaults": "",
".Xresources": "",
".bashprofile": "",
".bashrc": "",
".dmrc": "",
".ds_store": "",
".fasd": "",
".gitconfig": "",
".gitignore": "",
".jack-settings": "",
".mime.types": "",
".nvidia-settings-rc": "",
".pam_environment": "",
".profile": "",
".recently-used": "",
".selected_editor": "",
".vimrc": "",
".xinputrc": "",
"config": "",
"dropbox": "",
"exact-match-case-sensitive-1.txt": "X1",
"exact-match-case-sensitive-2": "X2",
"favicon.ico": "",
"gruntfile.coffee": "",
"gruntfile.js": "",
"gruntfile.ls": "",
"gulpfile.coffee": "",
"gulpfile.js": "",
"gulpfile.ls": "",
"ini": "",
"ledger": "",
"license": "",
"mimeapps.list": "",
"node_modules": "",
"procfile": "",
"react.jsx": "",
"user-dirs.dirs": "",
}
def devicon(file):
if file.is_directory: return dir_node_exact_matches.get(file.relative_path, '')
return file_node_exact_matches.get(file.relative_path, file_node_extensions.get(file.extension, ''))
if file.is_directory:
return dir_node_exact_matches.get(file.relative_path, "")
return file_node_exact_matches.get(
file.relative_path, file_node_extensions.get(file.extension, "")
)

View file

@ -1,22 +1,23 @@
import os
terminal=terminal=os.getenv('TERM')
if terminal != 'linux':
import ranger.api
from ranger.core.linemode import LinemodeBase
from devicons import *
@ranger.api.register_linemode
class DevIconsLinemode(LinemodeBase):
name = "devicons"
terminal = terminal = os.getenv("TERM")
if terminal != "linux":
import ranger.api
from ranger.core.linemode import LinemodeBase
from devicons import *
uses_metadata = False
@ranger.api.register_linemode
class DevIconsLinemode(LinemodeBase):
name = "devicons"
def filetitle(self, file, metadata):
return devicon(file) + ' ' + file.relative_path
uses_metadata = False
@ranger.api.register_linemode
class DevIconsLinemodeFile(LinemodeBase):
name = "filename"
def filetitle(self, file, metadata):
return devicon(file) + " " + file.relative_path
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