Merge kubuntu and ubuntu-i3 configs
This commit is contained in:
@@ -243,9 +243,8 @@ class cd(Command):
|
||||
|
||||
paths = self._tab_fuzzy_match(basepath, tokens)
|
||||
if not os.path.isabs(dest):
|
||||
paths_rel = self.fm.thisdir.path
|
||||
paths = [os.path.relpath(os.path.join(basepath, path), paths_rel)
|
||||
for path in paths]
|
||||
paths_rel = basepath
|
||||
paths = [os.path.relpath(path, paths_rel) for path in paths]
|
||||
else:
|
||||
paths_rel = ''
|
||||
return paths, paths_rel
|
||||
@@ -275,7 +274,7 @@ class cd(Command):
|
||||
return None
|
||||
if len(paths) == 1:
|
||||
return start + paths[0] + sep
|
||||
return [start + dirname + sep for dirname in paths]
|
||||
return [start + dirname for dirname in paths]
|
||||
|
||||
|
||||
class chain(Command):
|
||||
@@ -283,7 +282,6 @@ class chain(Command):
|
||||
|
||||
Calls multiple commands at once, separated by semicolons.
|
||||
"""
|
||||
resolve_macros = False
|
||||
|
||||
def execute(self):
|
||||
if not self.rest(1).strip():
|
||||
@@ -574,7 +572,7 @@ class default_linemode(Command):
|
||||
class quit(Command): # pylint: disable=redefined-builtin
|
||||
""":quit
|
||||
|
||||
Closes the current tab, if there's more than one tab.
|
||||
Closes the current tab, if there's only one tab.
|
||||
Otherwise quits if there are no tasks in progress.
|
||||
"""
|
||||
def _exit_no_work(self):
|
||||
@@ -593,7 +591,7 @@ class quit(Command): # pylint: disable=redefined-builtin
|
||||
class quit_bang(Command):
|
||||
""":quit!
|
||||
|
||||
Closes the current tab, if there's more than one tab.
|
||||
Closes the current tab, if there's only one tab.
|
||||
Otherwise force quits immediately.
|
||||
"""
|
||||
name = 'quit!'
|
||||
@@ -701,64 +699,6 @@ class delete(Command):
|
||||
self.fm.delete(files)
|
||||
|
||||
|
||||
class trash(Command):
|
||||
""":trash
|
||||
|
||||
Tries to move the selection or the files passed in arguments (if any) to
|
||||
the trash, using rifle rules with label "trash".
|
||||
The arguments use a shell-like escaping.
|
||||
|
||||
"Selection" is defined as all the "marked files" (by default, you
|
||||
can mark files with space or v). If there are no marked files,
|
||||
use the "current file" (where the cursor is)
|
||||
|
||||
When attempting to trash non-empty directories or multiple
|
||||
marked files, it will require a confirmation.
|
||||
"""
|
||||
|
||||
allow_abbrev = False
|
||||
escape_macros_for_shell = True
|
||||
|
||||
def execute(self):
|
||||
import shlex
|
||||
from functools import partial
|
||||
|
||||
def is_directory_with_files(path):
|
||||
return os.path.isdir(path) and not os.path.islink(path) and len(os.listdir(path)) > 0
|
||||
|
||||
if self.rest(1):
|
||||
files = shlex.split(self.rest(1))
|
||||
many_files = (len(files) > 1 or is_directory_with_files(files[0]))
|
||||
else:
|
||||
cwd = self.fm.thisdir
|
||||
tfile = self.fm.thisfile
|
||||
if not cwd or not tfile:
|
||||
self.fm.notify("Error: no file selected for deletion!", bad=True)
|
||||
return
|
||||
|
||||
# relative_path used for a user-friendly output in the confirmation.
|
||||
files = [f.relative_path for f in self.fm.thistab.get_selection()]
|
||||
many_files = (cwd.marked_items or is_directory_with_files(tfile.path))
|
||||
|
||||
confirm = self.fm.settings.confirm_on_delete
|
||||
if confirm != 'never' and (confirm != 'multiple' or many_files):
|
||||
self.fm.ui.console.ask(
|
||||
"Confirm deletion of: %s (y/N)" % ', '.join(files),
|
||||
partial(self._question_callback, files),
|
||||
('n', 'N', 'y', 'Y'),
|
||||
)
|
||||
else:
|
||||
# no need for a confirmation, just delete
|
||||
self.fm.execute_file(files, label='trash')
|
||||
|
||||
def tab(self, tabnum):
|
||||
return self._tab_directory_content()
|
||||
|
||||
def _question_callback(self, files, answer):
|
||||
if answer == 'y' or answer == 'Y':
|
||||
self.fm.execute_file(files, label='trash')
|
||||
|
||||
|
||||
class jump_non(Command):
|
||||
""":jump_non [-FLAGS...]
|
||||
|
||||
@@ -1056,7 +996,7 @@ class rename_append(Command):
|
||||
relpath = tfile.relative_path.replace(MACRO_DELIMITER, MACRO_DELIMITER_ESC)
|
||||
basename = tfile.basename.replace(MACRO_DELIMITER, MACRO_DELIMITER_ESC)
|
||||
|
||||
if basename.find('.') <= 0 or os.path.isdir(relpath):
|
||||
if basename.find('.') <= 0:
|
||||
self.fm.open_console('rename ' + relpath)
|
||||
return
|
||||
|
||||
@@ -1088,9 +1028,8 @@ class chmod(Command):
|
||||
def execute(self):
|
||||
mode_str = self.rest(1)
|
||||
if not mode_str:
|
||||
if self.quantifier is None:
|
||||
self.fm.notify("Syntax: chmod <octal number> "
|
||||
"or specify a quantifier", bad=True)
|
||||
if not self.quantifier:
|
||||
self.fm.notify("Syntax: chmod <octal number>", bad=True)
|
||||
return
|
||||
mode_str = str(self.quantifier)
|
||||
|
||||
@@ -1124,8 +1063,7 @@ class bulkrename(Command):
|
||||
After you close it, it will be executed.
|
||||
"""
|
||||
|
||||
def execute(self):
|
||||
# pylint: disable=too-many-locals,too-many-statements,too-many-branches
|
||||
def execute(self): # pylint: disable=too-many-locals,too-many-statements
|
||||
import sys
|
||||
import tempfile
|
||||
from ranger.container.file import File
|
||||
@@ -1134,57 +1072,46 @@ class bulkrename(Command):
|
||||
|
||||
# Create and edit the file list
|
||||
filenames = [f.relative_path for f in self.fm.thistab.get_selection()]
|
||||
with tempfile.NamedTemporaryFile(delete=False) as listfile:
|
||||
listpath = listfile.name
|
||||
if py3:
|
||||
listfile.write("\n".join(filenames).encode(
|
||||
encoding="utf-8", errors="surrogateescape"))
|
||||
else:
|
||||
listfile.write("\n".join(filenames))
|
||||
listfile = tempfile.NamedTemporaryFile(delete=False)
|
||||
listpath = listfile.name
|
||||
|
||||
if py3:
|
||||
listfile.write("\n".join(filenames).encode("utf-8"))
|
||||
else:
|
||||
listfile.write("\n".join(filenames))
|
||||
listfile.close()
|
||||
self.fm.execute_file([File(listpath)], app='editor')
|
||||
with (open(listpath, 'r', encoding="utf-8", errors="surrogateescape") if
|
||||
py3 else open(listpath, 'r')) as listfile:
|
||||
new_filenames = listfile.read().split("\n")
|
||||
listfile = open(listpath, 'r')
|
||||
new_filenames = listfile.read().split("\n")
|
||||
listfile.close()
|
||||
os.unlink(listpath)
|
||||
if all(a == b for a, b in zip(filenames, new_filenames)):
|
||||
self.fm.notify("No renaming to be done!")
|
||||
return
|
||||
|
||||
# Generate script
|
||||
with tempfile.NamedTemporaryFile() as cmdfile:
|
||||
script_lines = []
|
||||
script_lines.append("# This file will be executed when you close"
|
||||
" the editor.")
|
||||
script_lines.append("# Please double-check everything, clear the"
|
||||
" file to abort.")
|
||||
new_dirs = []
|
||||
for old, new in zip(filenames, new_filenames):
|
||||
if old != new:
|
||||
basepath, _ = os.path.split(new)
|
||||
if (basepath and basepath not in new_dirs
|
||||
and not os.path.isdir(basepath)):
|
||||
script_lines.append("mkdir -vp -- {dir}".format(
|
||||
dir=esc(basepath)))
|
||||
new_dirs.append(basepath)
|
||||
script_lines.append("mv -vi -- {old} {new}".format(
|
||||
old=esc(old), new=esc(new)))
|
||||
# Make sure not to forget the ending newline
|
||||
script_content = "\n".join(script_lines) + "\n"
|
||||
if py3:
|
||||
cmdfile.write(script_content.encode(encoding="utf-8",
|
||||
errors="surrogateescape"))
|
||||
else:
|
||||
cmdfile.write(script_content)
|
||||
cmdfile.flush()
|
||||
cmdfile = tempfile.NamedTemporaryFile()
|
||||
script_lines = []
|
||||
script_lines.append("# This file will be executed when you close the editor.\n")
|
||||
script_lines.append("# Please double-check everything, clear the file to abort.\n")
|
||||
script_lines.extend("mv -vi -- %s %s\n" % (esc(old), esc(new))
|
||||
for old, new in zip(filenames, new_filenames) if old != new)
|
||||
script_content = "".join(script_lines)
|
||||
if py3:
|
||||
cmdfile.write(script_content.encode("utf-8"))
|
||||
else:
|
||||
cmdfile.write(script_content)
|
||||
cmdfile.flush()
|
||||
|
||||
# Open the script and let the user review it, then check if the
|
||||
# script was modified by the user
|
||||
self.fm.execute_file([File(cmdfile.name)], app='editor')
|
||||
cmdfile.seek(0)
|
||||
script_was_edited = (script_content != cmdfile.read())
|
||||
# Open the script and let the user review it, then check if the script
|
||||
# was modified by the user
|
||||
self.fm.execute_file([File(cmdfile.name)], app='editor')
|
||||
cmdfile.seek(0)
|
||||
script_was_edited = (script_content != cmdfile.read())
|
||||
|
||||
# Do the renaming
|
||||
self.fm.run(['/bin/sh', cmdfile.name], flags='w')
|
||||
# Do the renaming
|
||||
self.fm.run(['/bin/sh', cmdfile.name], flags='w')
|
||||
cmdfile.close()
|
||||
|
||||
# Retag the files, but only if the script wasn't changed during review,
|
||||
# because only then we know which are the source and destination files.
|
||||
@@ -1303,7 +1230,7 @@ class copycmap(copymap):
|
||||
|
||||
|
||||
class copytmap(copymap):
|
||||
""":copytmap <keys> <newkeys1> [<newkeys2>...]
|
||||
""":copycmap <keys> <newkeys1> [<newkeys2>...]
|
||||
|
||||
Copies a "taskview" keybinding from <keys> to <newkeys>
|
||||
"""
|
||||
@@ -1322,69 +1249,30 @@ class unmap(Command):
|
||||
self.fm.ui.keymaps.unbind(self.context, arg)
|
||||
|
||||
|
||||
class uncmap(unmap):
|
||||
""":uncmap <keys> [<keys2>, ...]
|
||||
|
||||
Remove the given "console" mappings
|
||||
"""
|
||||
context = 'console'
|
||||
|
||||
|
||||
class cunmap(uncmap):
|
||||
class cunmap(unmap):
|
||||
""":cunmap <keys> [<keys2>, ...]
|
||||
|
||||
Remove the given "console" mappings
|
||||
|
||||
DEPRECATED in favor of uncmap.
|
||||
"""
|
||||
|
||||
def execute(self):
|
||||
self.fm.notify("cunmap is deprecated in favor of uncmap!")
|
||||
super(cunmap, self).execute()
|
||||
context = 'browser'
|
||||
|
||||
|
||||
class unpmap(unmap):
|
||||
""":unpmap <keys> [<keys2>, ...]
|
||||
class punmap(unmap):
|
||||
""":punmap <keys> [<keys2>, ...]
|
||||
|
||||
Remove the given "pager" mappings
|
||||
"""
|
||||
context = 'pager'
|
||||
|
||||
|
||||
class punmap(unpmap):
|
||||
""":punmap <keys> [<keys2>, ...]
|
||||
|
||||
Remove the given "pager" mappings
|
||||
|
||||
DEPRECATED in favor of unpmap.
|
||||
"""
|
||||
|
||||
def execute(self):
|
||||
self.fm.notify("punmap is deprecated in favor of unpmap!")
|
||||
super(punmap, self).execute()
|
||||
|
||||
|
||||
class untmap(unmap):
|
||||
""":untmap <keys> [<keys2>, ...]
|
||||
class tunmap(unmap):
|
||||
""":tunmap <keys> [<keys2>, ...]
|
||||
|
||||
Remove the given "taskview" mappings
|
||||
"""
|
||||
context = 'taskview'
|
||||
|
||||
|
||||
class tunmap(untmap):
|
||||
""":tunmap <keys> [<keys2>, ...]
|
||||
|
||||
Remove the given "taskview" mappings
|
||||
|
||||
DEPRECATED in favor of untmap.
|
||||
"""
|
||||
|
||||
def execute(self):
|
||||
self.fm.notify("tunmap is deprecated in favor of untmap!")
|
||||
super(tunmap, self).execute()
|
||||
|
||||
|
||||
class map_(Command):
|
||||
""":map <keysequence> <command>
|
||||
|
||||
@@ -1691,7 +1579,7 @@ class filter_stack(Command):
|
||||
elif subcommand == "clear":
|
||||
self.fm.thisdir.filter_stack = []
|
||||
elif subcommand == "rotate":
|
||||
rotate_by = int(self.arg(2) or self.quantifier or 1)
|
||||
rotate_by = int(self.arg(2) or 1)
|
||||
self.fm.thisdir.filter_stack = (
|
||||
self.fm.thisdir.filter_stack[-rotate_by:]
|
||||
+ self.fm.thisdir.filter_stack[:-rotate_by]
|
||||
@@ -1751,17 +1639,6 @@ class flat(Command):
|
||||
self.fm.thisdir.flat = level
|
||||
self.fm.thisdir.load_content()
|
||||
|
||||
|
||||
class reset_previews(Command):
|
||||
""":reset_previews
|
||||
|
||||
Reset the file previews.
|
||||
"""
|
||||
def execute(self):
|
||||
self.fm.previews = {}
|
||||
self.fm.ui.need_redraw = True
|
||||
|
||||
|
||||
# Version control commands
|
||||
# --------------------------------
|
||||
|
||||
@@ -1925,14 +1802,11 @@ class yank(Command):
|
||||
['xsel'],
|
||||
['xsel', '-b'],
|
||||
],
|
||||
'wl-copy': [
|
||||
['wl-copy'],
|
||||
],
|
||||
'pbcopy': [
|
||||
['pbcopy'],
|
||||
],
|
||||
}
|
||||
ordered_managers = ['pbcopy', 'wl-copy', 'xclip', 'xsel']
|
||||
ordered_managers = ['pbcopy', 'xclip', 'xsel']
|
||||
executables = get_executables()
|
||||
for manager in ordered_managers:
|
||||
if manager in executables:
|
||||
@@ -1960,34 +1834,3 @@ class yank(Command):
|
||||
in sorted(self.modes.keys())
|
||||
if mode
|
||||
)
|
||||
|
||||
|
||||
class paste_ext(Command):
|
||||
"""
|
||||
:paste_ext
|
||||
|
||||
Like paste but tries to rename conflicting files so that the
|
||||
file extension stays intact (e.g. file_.ext).
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def make_safe_path(dst):
|
||||
if not os.path.exists(dst):
|
||||
return dst
|
||||
|
||||
dst_name, dst_ext = os.path.splitext(dst)
|
||||
|
||||
if not dst_name.endswith("_"):
|
||||
dst_name += "_"
|
||||
if not os.path.exists(dst_name + dst_ext):
|
||||
return dst_name + dst_ext
|
||||
n = 0
|
||||
test_dst = dst_name + str(n)
|
||||
while os.path.exists(test_dst + dst_ext):
|
||||
n += 1
|
||||
test_dst = dst_name + str(n)
|
||||
|
||||
return test_dst + dst_ext
|
||||
|
||||
def execute(self):
|
||||
return self.fm.paste(make_safe_path=paste_ext.make_safe_path)
|
||||
|
||||
0
.config/ranger/plugins/__init__.py
Normal file
0
.config/ranger/plugins/__init__.py
Normal file
1
.config/ranger/plugins/ranger_devicons
Submodule
1
.config/ranger/plugins/ranger_devicons
Submodule
Submodule .config/ranger/plugins/ranger_devicons added at feb2d7a90f
@@ -1,10 +1,3 @@
|
||||
#
|
||||
# Please note that configuration files may change as ranger evolves.
|
||||
# It's completely up to you to keep them up to date.
|
||||
#
|
||||
# To stop ranger from loading both the default and your custom rc.conf,
|
||||
# please set the environment variable RANGER_LOAD_DEFAULT_RC to FALSE.
|
||||
#
|
||||
# ===================================================================
|
||||
# This file contains the default startup commands for ranger.
|
||||
# To change them, it is recommended to create either /etc/ranger/rc.conf
|
||||
@@ -41,7 +34,7 @@ set column_ratios 1,3,4
|
||||
set hidden_filter ^\.|\.(?:pyc|pyo|bak|swp)$|^lost\+found$|^__(py)?cache__$
|
||||
|
||||
# Show hidden files? You can toggle this by typing 'zh'
|
||||
set show_hidden false
|
||||
set show_hidden true
|
||||
|
||||
# Ask for a confirmation when running the "delete" command?
|
||||
# Valid values are "always", "never", "multiple" (default)
|
||||
@@ -78,7 +71,7 @@ set vcs_backend_svn disabled
|
||||
set vcs_msg_length 50
|
||||
|
||||
# Use one of the supported image preview protocols
|
||||
set preview_images false
|
||||
set preview_images true
|
||||
|
||||
# Set the preview image method. Supported methods:
|
||||
#
|
||||
@@ -121,7 +114,7 @@ set preview_images false
|
||||
# Preview images in full color with the external command "ueberzug".
|
||||
# Images are shown by using a child window.
|
||||
# Only for users who run X11 in GNU/Linux.
|
||||
set preview_images_method w3m
|
||||
set preview_images_method ueberzug
|
||||
|
||||
# Delay in seconds before displaying an image with the w3m method.
|
||||
# Increase it in case of experiencing display corruption.
|
||||
@@ -287,14 +280,14 @@ set clear_filters_on_dir_change false
|
||||
|
||||
# Disable displaying line numbers in main column.
|
||||
# Possible values: false, absolute, relative.
|
||||
set line_numbers false
|
||||
set line_numbers absolute
|
||||
|
||||
# When line_numbers=relative show the absolute line number in the
|
||||
# current line.
|
||||
set relative_current_zero false
|
||||
|
||||
# Start line numbers from 1 instead of 0
|
||||
set one_indexed false
|
||||
set one_indexed true
|
||||
|
||||
# Save tabs on exit
|
||||
set save_tabs_on_exit false
|
||||
@@ -460,6 +453,7 @@ map gu cd /usr
|
||||
map gd cd /dev
|
||||
map gl cd -r .
|
||||
map gL cd -r %f
|
||||
map gc cd ~/.config
|
||||
map go cd /opt
|
||||
map gv cd /var
|
||||
map gm cd /media
|
||||
@@ -547,7 +541,7 @@ map <A-Left> tab_move -1
|
||||
map gt tab_move 1
|
||||
map gT tab_move -1
|
||||
map gn tab_new
|
||||
map gc tab_close
|
||||
map gC tab_close
|
||||
map uq tab_restore
|
||||
map <a-1> tab_open 1
|
||||
map <a-2> tab_open 2
|
||||
@@ -764,3 +758,7 @@ tmap <delete> eval -q fm.ui.taskview.task_remove()
|
||||
tmap <C-l> redraw_window
|
||||
tmap <ESC> taskview_close
|
||||
copytmap <ESC> q Q w <C-c>
|
||||
|
||||
# Ranger devicons plugic
|
||||
default_linemode devicons
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
# directory | $1 is a directory
|
||||
# number <n> | change the number of this command to n
|
||||
# terminal | stdin, stderr and stdout are connected to a terminal
|
||||
# X | A graphical environment is available (darwin, Xorg, or Wayland)
|
||||
# X | $DISPLAY is not empty (i.e. Xorg runs)
|
||||
#
|
||||
# There are also pseudo-conditions which have a "side effect":
|
||||
# flag <flags> | Change how the program is run. See below.
|
||||
@@ -66,13 +66,13 @@ ext x?html?, has uzbl-tabbed, X, flag f = uzbl-tabbed -- "$@"
|
||||
ext x?html?, has uzbl-browser, X, flag f = uzbl-browser -- "$@"
|
||||
ext x?html?, has uzbl-core, X, flag f = uzbl-core -- "$@"
|
||||
ext x?html?, has midori, X, flag f = midori -- "$@"
|
||||
ext x?html?, has chromium-browser, X, flag f = chromium-browser -- "$@"
|
||||
ext x?html?, has chromium, X, flag f = chromium -- "$@"
|
||||
ext x?html?, has google-chrome, X, flag f = google-chrome -- "$@"
|
||||
ext x?html?, has opera, X, flag f = opera -- "$@"
|
||||
ext x?html?, has firefox, X, flag f = firefox -- "$@"
|
||||
ext x?html?, has seamonkey, X, flag f = seamonkey -- "$@"
|
||||
ext x?html?, has iceweasel, X, flag f = iceweasel -- "$@"
|
||||
ext x?html?, has chromium-browser, X, flag f = chromium-browser -- "$@"
|
||||
ext x?html?, has chromium, X, flag f = chromium -- "$@"
|
||||
ext x?html?, has google-chrome, X, flag f = google-chrome -- "$@"
|
||||
ext x?html?, has epiphany, X, flag f = epiphany -- "$@"
|
||||
ext x?html?, has konqueror, X, flag f = konqueror -- "$@"
|
||||
ext x?html?, has elinks, terminal = elinks "$@"
|
||||
@@ -98,7 +98,7 @@ ext exe = wine "$1"
|
||||
name ^[mM]akefile$ = make
|
||||
|
||||
#--------------------------------------------
|
||||
# Scripts
|
||||
# Code
|
||||
#-------------------------------------------
|
||||
ext py = python3 -- "$1"
|
||||
ext pl = perl -- "$1"
|
||||
@@ -131,7 +131,7 @@ mime ^video|audio, has totem, X, flag f = totem -- "$@"
|
||||
mime ^video|audio, has totem, X, flag f = totem --fullscreen -- "$@"
|
||||
|
||||
#--------------------------------------------
|
||||
# Video without X
|
||||
# Video without X:
|
||||
#-------------------------------------------
|
||||
mime ^video, terminal, !X, has mpv = mpv -- "$@"
|
||||
mime ^video, terminal, !X, has mplayer2 = mplayer2 -- "$@"
|
||||
@@ -167,20 +167,14 @@ ext djvu, has atril, X, flag f = atril -- "$@"
|
||||
ext djvu, has djview, X, flag f = djview -- "$@"
|
||||
|
||||
ext epub, has ebook-viewer, X, flag f = ebook-viewer -- "$@"
|
||||
ext epub, has zathura, X, flag f = zathura -- "$@"
|
||||
ext epub, has mupdf, X, flag f = mupdf -- "$@"
|
||||
ext mobi, has ebook-viewer, X, flag f = ebook-viewer -- "$@"
|
||||
|
||||
ext cbr, has zathura, X, flag f = zathura -- "$@"
|
||||
ext cbz, has zathura, X, flag f = zathura -- "$@"
|
||||
|
||||
#-------------------------------------------
|
||||
# Images
|
||||
# Image Viewing:
|
||||
#-------------------------------------------
|
||||
mime ^image/svg, has inkscape, X, flag f = inkscape -- "$@"
|
||||
mime ^image/svg, has display, X, flag f = display -- "$@"
|
||||
|
||||
mime ^image, has imv, X, flag f = imv -- "$@"
|
||||
mime ^image, has pqiv, X, flag f = pqiv -- "$@"
|
||||
mime ^image, has sxiv, X, flag f = sxiv -- "$@"
|
||||
mime ^image, has feh, X, flag f = feh -- "$@"
|
||||
@@ -190,7 +184,6 @@ mime ^image, has eog, X, flag f = eog -- "$@"
|
||||
mime ^image, has eom, X, flag f = eom -- "$@"
|
||||
mime ^image, has nomacs, X, flag f = nomacs -- "$@"
|
||||
mime ^image, has geeqie, X, flag f = geeqie -- "$@"
|
||||
mime ^image, has gpicview, X, flag f = gpicview -- "$@"
|
||||
mime ^image, has gwenview, X, flag f = gwenview -- "$@"
|
||||
mime ^image, has gimp, X, flag f = gimp -- "$@"
|
||||
ext xcf, X, flag f = gimp -- "$@"
|
||||
@@ -218,11 +211,6 @@ ext ace, has unace = for file in "$@"; do unace e "$file"; done
|
||||
ext rar, has unrar = unrar l "$1" | "$PAGER"
|
||||
ext rar, has unrar = for file in "$@"; do unrar x "$file"; done
|
||||
|
||||
#-------------------------------------------
|
||||
# Fonts
|
||||
#-------------------------------------------
|
||||
mime ^font, has fontforge, X, flag f = fontforge "$@"
|
||||
|
||||
#-------------------------------------------
|
||||
# Flag t fallback terminals
|
||||
#-------------------------------------------
|
||||
@@ -259,26 +247,10 @@ label wallpaper, number 12, mime ^image, has feh, X = feh --bg-tile "$1"
|
||||
label wallpaper, number 13, mime ^image, has feh, X = feh --bg-center "$1"
|
||||
label wallpaper, number 14, mime ^image, has feh, X = feh --bg-fill "$1"
|
||||
|
||||
#-------------------------------------------
|
||||
# Generic file openers
|
||||
#-------------------------------------------
|
||||
label open, has xdg-open = xdg-open -- "$@"
|
||||
label open, has open = open -- "$@"
|
||||
|
||||
# Define the editor for non-text files + pager as last action
|
||||
!mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ask
|
||||
label editor, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ${VISUAL:-$EDITOR} -- "$@"
|
||||
label pager, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"
|
||||
|
||||
|
||||
######################################################################
|
||||
# The actions below are left so low down in this file on purpose, so #
|
||||
# they are never triggered accidentally. #
|
||||
######################################################################
|
||||
|
||||
# Execute a file as program/script.
|
||||
# The very last action, so that it's never triggered accidentally, is to execute a program:
|
||||
mime application/x-executable = "$1"
|
||||
|
||||
# Move the file to trash using trash-cli.
|
||||
label trash, has trash-put = trash-put -- "$@"
|
||||
label trash = mkdir -p -- ${XDG_DATA_DIR:-$HOME/.ranger}/ranger-trash; mv -- "$@" ${XDG_DATA_DIR:-$HOME/.ranger}/ranger-trash
|
||||
|
||||
@@ -3,206 +3,129 @@
|
||||
set -o noclobber -o noglob -o nounset -o pipefail
|
||||
IFS=$'\n'
|
||||
|
||||
## If the option `use_preview_script` is set to `true`,
|
||||
## then this script will be called and its output will be displayed in ranger.
|
||||
## ANSI color codes are supported.
|
||||
## STDIN is disabled, so interactive scripts won't work properly
|
||||
# If the option `use_preview_script` is set to `true`,
|
||||
# then this script will be called and its output will be displayed in ranger.
|
||||
# ANSI color codes are supported.
|
||||
# STDIN is disabled, so interactive scripts won't work properly
|
||||
|
||||
## This script is considered a configuration file and must be updated manually.
|
||||
## It will be left untouched if you upgrade ranger.
|
||||
# This script is considered a configuration file and must be updated manually.
|
||||
# It will be left untouched if you upgrade ranger.
|
||||
|
||||
## Because of some automated testing we do on the script #'s for comments need
|
||||
## to be doubled up. Code that is commented out, because it's an alternative for
|
||||
## example, gets only one #.
|
||||
# Meanings of exit codes:
|
||||
# code | meaning | action of ranger
|
||||
# -----+------------+-------------------------------------------
|
||||
# 0 | success | Display stdout as preview
|
||||
# 1 | no preview | Display no preview at all
|
||||
# 2 | plain text | Display the plain content of the file
|
||||
# 3 | fix width | Don't reload when width changes
|
||||
# 4 | fix height | Don't reload when height changes
|
||||
# 5 | fix both | Don't ever reload
|
||||
# 6 | image | Display the image `$IMAGE_CACHE_PATH` points to as an image preview
|
||||
# 7 | image | Display the file directly as an image
|
||||
|
||||
## Meanings of exit codes:
|
||||
## code | meaning | action of ranger
|
||||
## -----+------------+-------------------------------------------
|
||||
## 0 | success | Display stdout as preview
|
||||
## 1 | no preview | Display no preview at all
|
||||
## 2 | plain text | Display the plain content of the file
|
||||
## 3 | fix width | Don't reload when width changes
|
||||
## 4 | fix height | Don't reload when height changes
|
||||
## 5 | fix both | Don't ever reload
|
||||
## 6 | image | Display the image `$IMAGE_CACHE_PATH` points to as an image preview
|
||||
## 7 | image | Display the file directly as an image
|
||||
|
||||
## Script arguments
|
||||
# Script arguments
|
||||
FILE_PATH="${1}" # Full path of the highlighted file
|
||||
PV_WIDTH="${2}" # Width of the preview pane (number of fitting characters)
|
||||
## shellcheck disable=SC2034 # PV_HEIGHT is provided for convenience and unused
|
||||
PV_HEIGHT="${3}" # Height of the preview pane (number of fitting characters)
|
||||
IMAGE_CACHE_PATH="${4}" # Full path that should be used to cache image preview
|
||||
PV_IMAGE_ENABLED="${5}" # 'True' if image previews are enabled, 'False' otherwise.
|
||||
|
||||
FILE_EXTENSION="${FILE_PATH##*.}"
|
||||
FILE_EXTENSION_LOWER="$(printf "%s" "${FILE_EXTENSION}" | tr '[:upper:]' '[:lower:]')"
|
||||
FILE_EXTENSION_LOWER=$(echo ${FILE_EXTENSION} | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
## Settings
|
||||
# Settings
|
||||
HIGHLIGHT_SIZE_MAX=262143 # 256KiB
|
||||
HIGHLIGHT_TABWIDTH=${HIGHLIGHT_TABWIDTH:-8}
|
||||
HIGHLIGHT_STYLE=${HIGHLIGHT_STYLE:-pablo}
|
||||
HIGHLIGHT_OPTIONS="--replace-tabs=${HIGHLIGHT_TABWIDTH} --style=${HIGHLIGHT_STYLE} ${HIGHLIGHT_OPTIONS:-}"
|
||||
PYGMENTIZE_STYLE=${PYGMENTIZE_STYLE:-autumn}
|
||||
OPENSCAD_IMGSIZE=${RNGR_OPENSCAD_IMGSIZE:-1000,1000}
|
||||
OPENSCAD_COLORSCHEME=${RNGR_OPENSCAD_COLORSCHEME:-Tomorrow Night}
|
||||
HIGHLIGHT_TABWIDTH=8
|
||||
HIGHLIGHT_STYLE='pablo'
|
||||
PYGMENTIZE_STYLE='autumn'
|
||||
|
||||
|
||||
handle_extension() {
|
||||
case "${FILE_EXTENSION_LOWER}" in
|
||||
## Archive
|
||||
# Archive
|
||||
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
|
||||
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
|
||||
atool --list -- "${FILE_PATH}" && exit 5
|
||||
bsdtar --list --file "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
rar)
|
||||
## Avoid password prompt by providing empty password
|
||||
# Avoid password prompt by providing empty password
|
||||
unrar lt -p- -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
7z)
|
||||
## Avoid password prompt by providing empty password
|
||||
# Avoid password prompt by providing empty password
|
||||
7z l -p -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## PDF
|
||||
# PDF
|
||||
pdf)
|
||||
## Preview as text conversion
|
||||
pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | \
|
||||
fmt -w "${PV_WIDTH}" && exit 5
|
||||
mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | \
|
||||
fmt -w "${PV_WIDTH}" && exit 5
|
||||
# Preview as text conversion
|
||||
pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | fmt -w ${PV_WIDTH} && exit 5
|
||||
mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | fmt -w ${PV_WIDTH} && exit 5
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## BitTorrent
|
||||
# BitTorrent
|
||||
torrent)
|
||||
transmission-show -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## OpenDocument
|
||||
# OpenDocument
|
||||
odt|ods|odp|sxw)
|
||||
## Preview as text conversion
|
||||
# Preview as text conversion
|
||||
odt2txt "${FILE_PATH}" && exit 5
|
||||
## Preview as markdown conversion
|
||||
pandoc -s -t markdown -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## XLSX
|
||||
xlsx)
|
||||
## Preview as csv conversion
|
||||
## Uses: https://github.com/dilshod/xlsx2csv
|
||||
xlsx2csv -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## HTML
|
||||
# HTML
|
||||
htm|html|xhtml)
|
||||
## Preview as text conversion
|
||||
# Preview as text conversion
|
||||
w3m -dump "${FILE_PATH}" && exit 5
|
||||
lynx -dump -- "${FILE_PATH}" && exit 5
|
||||
elinks -dump "${FILE_PATH}" && exit 5
|
||||
pandoc -s -t markdown -- "${FILE_PATH}" && exit 5
|
||||
;;
|
||||
|
||||
## JSON
|
||||
json)
|
||||
jq --color-output . "${FILE_PATH}" && exit 5
|
||||
python -m json.tool -- "${FILE_PATH}" && exit 5
|
||||
;;
|
||||
|
||||
## Direct Stream Digital/Transfer (DSDIFF) and wavpack aren't detected
|
||||
## by file(1).
|
||||
dff|dsf|wv|wvc)
|
||||
mediainfo "${FILE_PATH}" && exit 5
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
;; # Continue with next handler on failure
|
||||
esac
|
||||
}
|
||||
|
||||
handle_image() {
|
||||
## Size of the preview if there are multiple options or it has to be
|
||||
## rendered from vector graphics. If the conversion program allows
|
||||
## specifying only one dimension while keeping the aspect ratio, the width
|
||||
## will be used.
|
||||
local DEFAULT_SIZE="1920x1080"
|
||||
|
||||
local mimetype="${1}"
|
||||
case "${mimetype}" in
|
||||
## SVG
|
||||
# image/svg+xml|image/svg)
|
||||
# convert -- "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# SVG
|
||||
# image/svg+xml)
|
||||
# convert "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6
|
||||
# exit 1;;
|
||||
|
||||
## DjVu
|
||||
# image/vnd.djvu)
|
||||
# ddjvu -format=tiff -quality=90 -page=1 -size="${DEFAULT_SIZE}" \
|
||||
# - "${IMAGE_CACHE_PATH}" < "${FILE_PATH}" \
|
||||
# && exit 6 || exit 1;;
|
||||
|
||||
## Image
|
||||
# Image
|
||||
image/*)
|
||||
local orientation
|
||||
orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FILE_PATH}" )"
|
||||
## If orientation data is present and the image actually
|
||||
## needs rotating ("1" means no rotation)...
|
||||
# If orientation data is present and the image actually
|
||||
# needs rotating ("1" means no rotation)...
|
||||
if [[ -n "$orientation" && "$orientation" != 1 ]]; then
|
||||
## ...auto-rotate the image according to the EXIF data.
|
||||
# ...auto-rotate the image according to the EXIF data.
|
||||
convert -- "${FILE_PATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
|
||||
fi
|
||||
|
||||
## `w3mimgdisplay` will be called for all images (unless overriden
|
||||
## as above), but might fail for unsupported types.
|
||||
# `w3mimgdisplay` will be called for all images (unless overriden as above),
|
||||
# but might fail for unsupported types.
|
||||
exit 7;;
|
||||
|
||||
## Video
|
||||
# Video
|
||||
# video/*)
|
||||
# # Thumbnail
|
||||
# ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
|
||||
# exit 1;;
|
||||
|
||||
## PDF
|
||||
# PDF
|
||||
# application/pdf)
|
||||
# pdftoppm -f 1 -l 1 \
|
||||
# -scale-to-x "${DEFAULT_SIZE%x*}" \
|
||||
# -scale-to-x 1920 \
|
||||
# -scale-to-y -1 \
|
||||
# -singlefile \
|
||||
# -jpeg -tiffcompression jpeg \
|
||||
# -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \
|
||||
# && exit 6 || exit 1;;
|
||||
|
||||
|
||||
## ePub, MOBI, FB2 (using Calibre)
|
||||
# application/epub+zip|application/x-mobipocket-ebook|\
|
||||
# application/x-fictionbook+xml)
|
||||
# # ePub (using https://github.com/marianosimone/epub-thumbnailer)
|
||||
# epub-thumbnailer "${FILE_PATH}" "${IMAGE_CACHE_PATH}" \
|
||||
# "${DEFAULT_SIZE%x*}" && exit 6
|
||||
# ebook-meta --get-cover="${IMAGE_CACHE_PATH}" -- "${FILE_PATH}" \
|
||||
# >/dev/null && exit 6
|
||||
# exit 1;;
|
||||
|
||||
## Font
|
||||
application/font*|application/*opentype)
|
||||
preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png"
|
||||
if fontimage -o "${preview_png}" \
|
||||
--pixelsize "120" \
|
||||
--fontname \
|
||||
--pixelsize "80" \
|
||||
--text " ABCDEFGHIJKLMNOPQRSTUVWXYZ " \
|
||||
--text " abcdefghijklmnopqrstuvwxyz " \
|
||||
--text " 0123456789.:,;(*!?') ff fl fi ffi ffl " \
|
||||
--text " The quick brown fox jumps over the lazy dog. " \
|
||||
"${FILE_PATH}";
|
||||
then
|
||||
convert -- "${preview_png}" "${IMAGE_CACHE_PATH}" \
|
||||
&& rm "${preview_png}" \
|
||||
&& exit 6
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
## Preview archives using the first image inside.
|
||||
## (Very useful for comic book collections for example.)
|
||||
# Preview archives using the first image inside.
|
||||
# (Very useful for comic book collections for example.)
|
||||
# application/zip|application/x-rar|application/x-7z-compressed|\
|
||||
# application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar)
|
||||
# local fn=""; local fe=""
|
||||
@@ -238,60 +161,14 @@ handle_image() {
|
||||
# [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}"
|
||||
# ;;
|
||||
esac
|
||||
|
||||
# openscad_image() {
|
||||
# TMPPNG="$(mktemp -t XXXXXX.png)"
|
||||
# openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \
|
||||
# --imgsize="${OPENSCAD_IMGSIZE/x/,}" \
|
||||
# -o "${TMPPNG}" "${1}"
|
||||
# mv "${TMPPNG}" "${IMAGE_CACHE_PATH}"
|
||||
# }
|
||||
|
||||
# case "${FILE_EXTENSION_LOWER}" in
|
||||
# ## 3D models
|
||||
# ## OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH}
|
||||
# ## is hardcoded as jpeg. So we make a tempfile.png and just
|
||||
# ## move/rename it to jpg. This works because image libraries are
|
||||
# ## smart enough to handle it.
|
||||
# csg|scad)
|
||||
# openscad_image "${FILE_PATH}" && exit 6
|
||||
# ;;
|
||||
# 3mf|amf|dxf|off|stl)
|
||||
# openscad_image <(echo "import(\"${FILE_PATH}\");") && exit 6
|
||||
# ;;
|
||||
# esac
|
||||
}
|
||||
|
||||
handle_mime() {
|
||||
local mimetype="${1}"
|
||||
case "${mimetype}" in
|
||||
## RTF and DOC
|
||||
text/rtf|*msword)
|
||||
## Preview as text conversion
|
||||
## note: catdoc does not always work for .doc files
|
||||
## catdoc: http://www.wagner.pp.ru/~vitus/software/catdoc/
|
||||
catdoc -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## DOCX, ePub, FB2 (using markdown)
|
||||
## You might want to remove "|epub" and/or "|fb2" below if you have
|
||||
## uncommented other methods to preview those formats
|
||||
*wordprocessingml.document|*/epub+zip|*/x-fictionbook+xml)
|
||||
## Preview as markdown conversion
|
||||
pandoc -s -t markdown -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## XLS
|
||||
*ms-excel)
|
||||
## Preview as csv conversion
|
||||
## xls2csv comes with catdoc:
|
||||
## http://www.wagner.pp.ru/~vitus/software/catdoc/
|
||||
xls2csv -- "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## Text
|
||||
# Text
|
||||
text/* | */xml)
|
||||
## Syntax highlight
|
||||
# Syntax highlight
|
||||
if [[ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
|
||||
exit 2
|
||||
fi
|
||||
@@ -302,30 +179,19 @@ handle_mime() {
|
||||
local pygmentize_format='terminal'
|
||||
local highlight_format='ansi'
|
||||
fi
|
||||
env HIGHLIGHT_OPTIONS="${HIGHLIGHT_OPTIONS}" highlight \
|
||||
--out-format="${highlight_format}" \
|
||||
--force -- "${FILE_PATH}" && exit 5
|
||||
env COLORTERM=8bit bat --color=always --style="plain" \
|
||||
-- "${FILE_PATH}" && exit 5
|
||||
pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}"\
|
||||
-- "${FILE_PATH}" && exit 5
|
||||
highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \
|
||||
--style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}" && exit 5
|
||||
# pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "${FILE_PATH}" && exit 5
|
||||
exit 2;;
|
||||
|
||||
## DjVu
|
||||
image/vnd.djvu)
|
||||
## Preview as text conversion (requires djvulibre)
|
||||
djvutxt "${FILE_PATH}" | fmt -w "${PV_WIDTH}" && exit 5
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## Image
|
||||
# Image
|
||||
image/*)
|
||||
## Preview as text conversion
|
||||
# Preview as text conversion
|
||||
# img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
exit 1;;
|
||||
|
||||
## Video and audio
|
||||
# Video and audio
|
||||
video/* | audio/*)
|
||||
mediainfo "${FILE_PATH}" && exit 5
|
||||
exiftool "${FILE_PATH}" && exit 5
|
||||
|
||||
Reference in New Issue
Block a user