From ba018e3ddd4eb8c6155f5136bb932e040db20e96 Mon Sep 17 00:00:00 2001 From: katherine Date: Tue, 17 Jan 2017 05:55:51 -0700 Subject: update ranger files lot's changed since last time doing this X_X --- .config/ranger/commands.py | 580 ++++++++++++++++++++++++++++++++------------- .config/ranger/rc.conf | 209 ++++++++++------ .config/ranger/scope.sh | 52 +++- 3 files changed, 589 insertions(+), 252 deletions(-) mode change 100644 => 100755 .config/ranger/commands.py (limited to '.config/ranger') diff --git a/.config/ranger/commands.py b/.config/ranger/commands.py old mode 100644 new mode 100755 index 7ffd7f5..a384f42 --- a/.config/ranger/commands.py +++ b/.config/ranger/commands.py @@ -1,7 +1,12 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2009-2013 Roman Zimbelmann +# This file is part of ranger, the console file manager. # This configuration file is licensed under the same terms as ranger. # =================================================================== +# +# NOTE: If you copied this file to ~/.config/ranger/commands_full.py, +# then it will NOT be loaded by ranger, and only serve as a reference. +# +# =================================================================== # This file contains ranger's commands. # It's all in python; lines beginning with # are comments. # @@ -16,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 @@ -42,9 +49,9 @@ # the user pressed 6X, self.quantifier will be 6. # self.arg(n): The n-th argument, or an empty string if it doesn't exist. # self.rest(n): The n-th argument plus everything that followed. For example, -# If the command was "search foo bar a b c", rest(2) will be "bar a b c" -# self.start(n): The n-th argument and anything before it. For example, -# If the command was "search foo bar a b c", rest(2) will be "bar a b c" +# if the command was "search foo bar a b c", rest(2) will be "bar a b c" +# self.start(n): Anything before the n-th argument. For example, if the +# command was "search foo bar a b c", start(2) will be "search foo" # # =================================================================== # And this is a little reference for common ranger functions and objects: @@ -78,6 +85,7 @@ from ranger.api.commands import * + class alias(Command): """:alias @@ -93,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] @@ -107,7 +125,8 @@ class cd(Command): self.shift() destination = os.path.realpath(self.rest(1)) if os.path.isfile(destination): - destination = os.path.dirname(destination) + self.fm.select_file(destination) + return else: destination = self.rest(1) @@ -119,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 @@ -127,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('~'): @@ -147,14 +166,15 @@ 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 pass else: dirnames.sort() - dirnames = bookmarks + dirnames + if self.fm.settings.cd_bookmarks: + dirnames = bookmarks + dirnames # no results, return None if len(dirnames) == 0: @@ -175,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) @@ -190,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) @@ -208,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() @@ -218,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): @@ -321,36 +338,52 @@ class set_(Command): """:set