From d721c7a5f9fa2c26e97e616542b516daced4dc08 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sun, 6 Aug 2017 00:36:31 +0700 Subject: Update 2017-08-06 --- ranger/.config/ranger/commands.py | 9 +- ranger/.config/ranger/commands_full.py | 356 ++++++++++++++++----------------- ranger/.config/ranger/rc.conf | 102 +++++++--- ranger/.config/ranger/rifle.conf | 45 +++-- ranger/.config/ranger/scope.sh | 56 ++++-- 5 files changed, 323 insertions(+), 245 deletions(-) (limited to 'ranger/.config') diff --git a/ranger/.config/ranger/commands.py b/ranger/.config/ranger/commands.py index 2df405f..1386e84 100644 --- a/ranger/.config/ranger/commands.py +++ b/ranger/.config/ranger/commands.py @@ -8,13 +8,15 @@ from ranger.api.commands import * # A simple command for demonstration purposes follows. -#------------------------------------------------------------------------------ +# ----------------------------------------------------------------------------- # You can import any python module as needed. import os # Any class that is a subclass of "Command" will be integrated into ranger as a # command. Try typing ":my_edit" in ranger! + + class my_edit(Command): # The so-called doc-string of the class will be visible in the built-in # help that is accessible by typing "?c" inside ranger. @@ -37,7 +39,7 @@ class my_edit(Command): # reference to the currently selected file. target_filename = self.fm.thisfile.path - # This is a generic function to print text in ranger. + # This is a generic function to print text in ranger. self.fm.notify("Let's edit the file " + target_filename + "!") # Using bad=True in fm.notify allows you to print error messages: @@ -52,7 +54,8 @@ class my_edit(Command): # The tab method is called when you press tab, and should return a list of # suggestions that the user will tab through. - def tab(self): + # tabnum is 1 for and -1 for by default + def tab(self, tabnum): # This is a generic tab-completion function that iterates through the # content of the current directory. return self._tab_directory_content() diff --git a/ranger/.config/ranger/commands_full.py b/ranger/.config/ranger/commands_full.py index cb62a62..a384f42 100644 --- a/ranger/.config/ranger/commands_full.py +++ b/ranger/.config/ranger/commands_full.py @@ -21,10 +21,12 @@ # =================================================================== # Every class defined here which is a subclass of `Command' will be used as a # command in ranger. Several methods are defined to interface with ranger: -# execute(): called when the command is executed. -# cancel(): called when closing the console. -# tab(): called when is pressed. -# quick(): called after each keypress. +# execute(): called when the command is executed. +# cancel(): called when closing the console. +# tab(tabnum): called when is pressed. +# quick(): called after each keypress. +# +# tab() argument tabnum is 1 for and -1 for by default # # The return values for tab() can be either: # None: There is no tab completion @@ -83,6 +85,7 @@ from ranger.api.commands import * + class alias(Command): """:alias @@ -98,6 +101,16 @@ class alias(Command): else: self.fm.commands.alias(self.arg(1), self.rest(2)) + +class echo(Command): + """:echo + + Display the text in the statusbar. + """ + def execute(self): + self.fm.notify(self.rest(1)) + + class cd(Command): """:cd [-r] @@ -125,7 +138,7 @@ class cd(Command): else: self.fm.cd(destination) - def tab(self): + def tab(self, tabnum): import os from os.path import dirname, basename, expanduser, join @@ -133,7 +146,7 @@ class cd(Command): rel_dest = self.rest(1) bookmarks = [v.path for v in self.fm.bookmarks.dct.values() - if rel_dest in v.path ] + if rel_dest in v.path] # expand the tilde into the user directory if rel_dest.startswith('~'): @@ -153,7 +166,7 @@ class cd(Command): # are we in the middle of the filename? else: _, dirnames, _ = next(os.walk(abs_dirname)) - dirnames = [dn for dn in dirnames \ + dirnames = [dn for dn in dirnames if dn.startswith(rel_basename)] except (OSError, StopIteration): # os.walk found nothing @@ -182,7 +195,7 @@ class chain(Command): Calls multiple commands at once, separated by semicolons. """ def execute(self): - for command in self.rest(1).split(";"): + for command in [s.strip() for s in self.rest(1).split(";")]: self.fm.execute_console(command) @@ -197,14 +210,10 @@ class shell(Command): flags = '' command = self.rest(1) - if not command and 'p' in flags: - command = 'cat %f' if command: - if '%' in command: - command = self.fm.substitute_macros(command, escape=True) self.fm.execute_command(command, flags=flags) - def tab(self): + def tab(self, tabnum): from ranger.ext.get_executables import get_executables if self.arg(1) and self.arg(1)[0] == '-': command = self.rest(2) @@ -215,7 +224,7 @@ class shell(Command): try: position_of_last_space = command.rindex(" ") except ValueError: - return (start + program + ' ' for program \ + return (start + program + ' ' for program in get_executables() if program.startswith(command)) if position_of_last_space == len(command) - 1: selection = self.fm.thistab.get_selection() @@ -225,20 +234,21 @@ class shell(Command): return self.line + '%s ' else: before_word, start_of_word = self.line.rsplit(' ', 1) - return (before_word + ' ' + file.shell_escaped_basename \ - for file in self.fm.thisdir.files \ + return (before_word + ' ' + file.shell_escaped_basename + for file in self.fm.thisdir.files or [] if file.shell_escaped_basename.startswith(start_of_word)) + class open_with(Command): def execute(self): app, flags, mode = self._get_app_flags_mode(self.rest(1)) self.fm.execute_file( - files = [f for f in self.fm.thistab.get_selection()], - app = app, - flags = flags, - mode = mode) + files=[f for f in self.fm.thistab.get_selection()], + app=app, + flags=flags, + mode=mode) - def tab(self): + def tab(self, tabnum): return self._tab_through_executables() def _get_app_flags_mode(self, string): @@ -328,26 +338,32 @@ class set_(Command): """:set