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 from ranger.api.commands import Command
class paste_as_root(Command): class paste_as_root(Command):
def execute(self): def execute(self):
if self.fm.do_cut: if self.fm.do_cut:
self.fm.execute_console('shell sudo mv %c .') self.fm.execute_console("shell sudo mv %c .")
else: else:
self.fm.execute_console('shell sudo cp -r %c .') self.fm.execute_console("shell sudo cp -r %c .")
class fzf_select(Command): class fzf_select(Command):
""" """
@ -17,9 +19,11 @@ class fzf_select(Command):
See: https://github.com/junegunn/fzf See: https://github.com/junegunn/fzf
""" """
def execute(self): def execute(self):
import subprocess import subprocess
import os.path import os.path
if self.quantifier: if self.quantifier:
# match only directories # 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 \
@ -28,10 +32,12 @@ class fzf_select(Command):
# match files and directories # 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'" -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() stdout, stderr = fzf.communicate()
if fzf.returncode == 0: 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): if os.path.isdir(fzf_file):
self.fm.cd(fzf_file) self.fm.cd(fzf_file)
else: else:

View file

@ -3,217 +3,220 @@
# These glyphs, and the mapping of file extensions to glyphs # These glyphs, and the mapping of file extensions to glyphs
# has been copied from the vimscript code that is present in # has been copied from the vimscript code that is present in
# https://github.com/ryanoasis/vim-devicons # 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 # 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: # My advice is to use NerdFonts which can be found here:
# https://github.com/ryanoasis/nerd-fonts # https://github.com/ryanoasis/nerd-fonts
file_node_extensions = { file_node_extensions = {
'7z' : '', "7z": "",
'ai' : '', "ai": "",
'apk' : '', "apk": "",
'avi' : '', "avi": "",
'bat' : '', "bat": "",
'bmp' : '', "bmp": "",
'bz2' : '', "bz2": "",
'c' : '', "c": "",
'c++' : '', "c++": "",
'cab' : '', "cab": "",
'cc' : '', "cc": "",
'clj' : '', "clj": "",
'cljc' : '', "cljc": "",
'cljs' : '', "cljs": "",
'coffee' : '', "coffee": "",
'conf' : '', "conf": "",
'cp' : '', "cp": "",
'cpio' : '', "cpio": "",
'cpp' : '', "cpp": "",
'css' : '', "css": "",
'cxx' : '', "cxx": "",
'd' : '', "d": "",
'dart' : '', "dart": "",
'db' : '', "db": "",
'deb' : '', "deb": "",
'diff' : '', "diff": "",
'dump' : '', "dump": "",
'edn' : '', "edn": "",
'ejs' : '', "ejs": "",
'epub' : '', "epub": "",
'erl' : '', "erl": "",
'f#' : '', "f#": "",
'fish' : '', "fish": "",
'flac' : '', "flac": "",
'flv' : '', "flv": "",
'fs' : '', "fs": "",
'fsi' : '', "fsi": "",
'fsscript' : '', "fsscript": "",
'fsx' : '', "fsx": "",
'gem' : '', "gem": "",
'gif' : '', "gif": "",
'go' : '', "go": "",
'gz' : '', "gz": "",
'gzip' : '', "gzip": "",
'hbs' : '', "hbs": "",
'hrl' : '', "hrl": "",
'hs' : '', "hs": "",
'htm' : '', "htm": "",
'html' : '', "html": "",
'ico' : '', "ico": "",
'ini' : '', "ini": "",
'java' : '', "java": "",
'jl' : '', "jl": "",
'jpeg' : '', "jpeg": "",
'jpg' : '', "jpg": "",
'js' : '', "js": "",
'json' : '', "json": "",
'jsx' : '', "jsx": "",
'less' : '', "less": "",
'lha' : '', "lha": "",
'lhs' : '', "lhs": "",
'log' : '', "log": "",
'lua' : '', "lua": "",
'lzh' : '', "lzh": "",
'lzma' : '', "lzma": "",
'markdown' : '', "markdown": "",
'md' : '', "md": "",
'mkv' : '', "mkv": "",
'ml' : 'λ', "ml": "λ",
'mli' : 'λ', "mli": "λ",
'mov' : '', "mov": "",
'mp3' : '', "mp3": "",
'mp4' : '', "mp4": "",
'mpeg' : '', "mpeg": "",
'mpg' : '', "mpg": "",
'mustache' : '', "mustache": "",
'ogg' : '', "ogg": "",
'pdf' : '', "pdf": "",
'php' : '', "php": "",
'pl' : '', "pl": "",
'pm' : '', "pm": "",
'png' : '', "png": "",
'psb' : '', "psb": "",
'psd' : '', "psd": "",
'py' : '', "py": "",
'pyc' : '', "pyc": "",
'pyd' : '', "pyd": "",
'pyo' : '', "pyo": "",
'rar' : '', "rar": "",
'rb' : '', "rb": "",
'rc' : '', "rc": "",
'rlib' : '', "rlib": "",
'rpm' : '', "rpm": "",
'rs' : '', "rs": "",
'rss' : '', "rss": "",
'scala' : '', "scala": "",
'scss' : '', "scss": "",
'sh' : '', "sh": "",
'slim' : '', "slim": "",
'sln' : '', "sln": "",
'sql' : '', "sql": "",
'styl' : '', "styl": "",
'suo' : '', "suo": "",
't' : '', "t": "",
'tar' : '', "tar": "",
'tgz' : '', "tgz": "",
'ts' : '', "ts": "",
'twig' : '', "twig": "",
'vim' : '', "vim": "",
'vimrc' : '', "vimrc": "",
'wav' : '', "wav": "",
'xml' : '', "xml": "",
'xul' : '', "xul": "",
'xz' : '', "xz": "",
'yml' : '', "yml": "",
'zip' : '', "zip": "",
} }
dir_node_exact_matches = { dir_node_exact_matches = {
# English # English
'.git' : '', ".git": "",
'Desktop' : '', "Desktop": "",
'Documents' : '', "Documents": "",
'Downloads' : '', "Downloads": "",
'Dropbox' : '', "Dropbox": "",
'Music' : '', "Music": "",
'Pictures' : '', "Pictures": "",
'Public' : '', "Public": "",
'Templates' : '', "Templates": "",
'Videos' : '', "Videos": "",
# French # French
'Bureau' : '', "Bureau": "",
'Documents' : '', "Documents": "",
'Images' : '', "Images": "",
'Musique' : '', "Musique": "",
'Publique' : '', "Publique": "",
'Téléchargements' : '', "Téléchargements": "",
'Vidéos' : '', "Vidéos": "",
# Portuguese # Portuguese
'Documentos' : '', "Documentos": "",
'Imagens' : '', "Imagens": "",
'Modelos' : '', "Modelos": "",
'Música' : '', "Música": "",
'Público' : '', "Público": "",
'Vídeos' : '', "Vídeos": "",
'Área de trabalho' : '', "Área de trabalho": "",
# Italian # Italian
'Documenti' : '', "Documenti": "",
'Immagini' : '', "Immagini": "",
'Modelli' : '', "Modelli": "",
'Musica' : '', "Musica": "",
'Pubblici' : '', "Pubblici": "",
'Scaricati' : '', "Scaricati": "",
'Scrivania' : '', "Scrivania": "",
'Video' : '', "Video": "",
# German # German
'Bilder' : '', "Bilder": "",
'Dokumente' : '', "Dokumente": "",
'Musik' : '', "Musik": "",
'Schreibtisch' : '', "Schreibtisch": "",
'Vorlagen' : '', "Vorlagen": "",
'Öffentlich' : '', "Öffentlich": "",
} }
file_node_exact_matches = { file_node_exact_matches = {
'.Xdefaults' : '', ".Xdefaults": "",
'.Xresources' : '', ".Xresources": "",
'.bashprofile' : '', ".bashprofile": "",
'.bashrc' : '', ".bashrc": "",
'.dmrc' : '', ".dmrc": "",
'.ds_store' : '', ".ds_store": "",
'.fasd' : '', ".fasd": "",
'.gitconfig' : '', ".gitconfig": "",
'.gitignore' : '', ".gitignore": "",
'.jack-settings' : '', ".jack-settings": "",
'.mime.types' : '', ".mime.types": "",
'.nvidia-settings-rc' : '', ".nvidia-settings-rc": "",
'.pam_environment' : '', ".pam_environment": "",
'.profile' : '', ".profile": "",
'.recently-used' : '', ".recently-used": "",
'.selected_editor' : '', ".selected_editor": "",
'.vimrc' : '', ".vimrc": "",
'.xinputrc' : '', ".xinputrc": "",
'config' : '', "config": "",
'dropbox' : '', "dropbox": "",
'exact-match-case-sensitive-1.txt' : 'X1', "exact-match-case-sensitive-1.txt": "X1",
'exact-match-case-sensitive-2' : 'X2', "exact-match-case-sensitive-2": "X2",
'favicon.ico' : '', "favicon.ico": "",
'gruntfile.coffee' : '', "gruntfile.coffee": "",
'gruntfile.js' : '', "gruntfile.js": "",
'gruntfile.ls' : '', "gruntfile.ls": "",
'gulpfile.coffee' : '', "gulpfile.coffee": "",
'gulpfile.js' : '', "gulpfile.js": "",
'gulpfile.ls' : '', "gulpfile.ls": "",
'ini' : '', "ini": "",
'ledger' : '', "ledger": "",
'license' : '', "license": "",
'mimeapps.list' : '', "mimeapps.list": "",
'node_modules' : '', "node_modules": "",
'procfile' : '', "procfile": "",
'react.jsx' : '', "react.jsx": "",
'user-dirs.dirs' : '', "user-dirs.dirs": "",
} }
def devicon(file): def devicon(file):
if file.is_directory: return dir_node_exact_matches.get(file.relative_path, '') if file.is_directory:
return file_node_exact_matches.get(file.relative_path, file_node_extensions.get(file.extension, '')) 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,6 +1,7 @@
import os import os
terminal=terminal=os.getenv('TERM')
if terminal != 'linux': terminal = terminal = os.getenv("TERM")
if terminal != "linux":
import ranger.api import ranger.api
from ranger.core.linemode import LinemodeBase from ranger.core.linemode import LinemodeBase
from devicons import * from devicons import *
@ -12,11 +13,11 @@ if terminal != 'linux':
uses_metadata = False uses_metadata = False
def filetitle(self, file, metadata): def filetitle(self, file, metadata):
return devicon(file) + ' ' + file.relative_path return devicon(file) + " " + file.relative_path
@ranger.api.register_linemode @ranger.api.register_linemode
class DevIconsLinemodeFile(LinemodeBase): class DevIconsLinemodeFile(LinemodeBase):
name = "filename" name = "filename"
def filetitle(self, file, metadata): def filetitle(self, file, metadata):
return devicon(file) + ' ' + file.relative_path return devicon(file) + " " + file.relative_path