THEAARBS ranger commands_full

Raw

# -*- coding: utf-8 -*-
# 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.
#
# Note that additional commands are automatically generated from the methods
# of the class ranger.core.actions.Actions.
#
# You can customize commands in the file ~/.config/ranger/commands.py.
# It has the same syntax as this file.  In fact, you can just copy this
# file there with `ranger --copy-config=commands' and make your modifications.
# But make sure you update your configs when you update ranger.
#
# ===================================================================
# 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 <TAB> is pressed.
#   quick():   called after each keypress.
#
# The return values for tab() can be either:
#   None: There is no tab completion
#   A string: Change the console to this string
#   A list/tuple/generator: cycle through every item in it
#
# The return value for quick() can be:
#   False: Nothing happens
#   True: Execute the command afterwards
#
# The return value for execute() and cancel() doesn't matter.
#
# ===================================================================
# Commands have certain attributes and methods that facilitate parsing of
# the arguments:
#
# self.line: The whole line that was written in the console.
# self.args: A list of all (space-separated) arguments to the command.
# self.quantifier: If this command was mapped to the key "X" and
#      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): 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:
#
# self.fm: A reference to the "fm" object which contains most information
#      about ranger.
# self.fm.notify(string): Print the given string on the screen.
# self.fm.notify(string, bad=True): Print the given string in RED.
# self.fm.reload_cwd(): Reload the current working directory.
# self.fm.thisdir: The current working directory. (A File object.)
# self.fm.thisfile: The current file. (A File object too.)
# self.fm.thistab.get_selection(): A list of all selected files.
# self.fm.execute_console(string): Execute the string as a ranger command.
# self.fm.open_console(string): Open the console with the given string
#      already typed in for you.
# self.fm.move(direction): Moves the cursor in the given direction, which
#      can be something like down=3, up=5, right=1, left=1, to=6, ...
#
# File objects (for example self.fm.thisfile) have these useful attributes and
# methods:
#
# cf.path: The path to the file.
# cf.basename: The base name only.
# cf.load_content(): Force a loading of the directories content (which
#      obviously works with directories only)
# cf.is_directory: True/False depending on whether it's a directory.
#
# For advanced commands it is unavoidable to dive a bit into the source code
# of ranger.
# ===================================================================

from ranger.api.commands import *

class alias(Command): """:alias <newcommand> <oldcommand> Copies the oldcommand as newcommand. """

context <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">browser</span><span style="color:#e6db74">&#39;</span>
resolve_macros <span style="color:#f92672">=</span> False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">or</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">2</span>):
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">Syntax: alias &lt;newcommand&gt; &lt;oldcommand&gt;</span><span style="color:#e6db74">&#39;</span>, bad<span style="color:#f92672">=</span>True)
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>commands<span style="color:#f92672">.</span>alias(self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>), self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">2</span>))

class cd(Command): """:cd [-r] <dirname> The cd command changes the directory. The command 'cd -' is equivalent to typing ``. Using the option "-r" will get you to the real path. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#f92672">import</span> os.path
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-r</span><span style="color:#e6db74">&#39;</span>:
        self<span style="color:#f92672">.</span>shift()
        destination <span style="color:#f92672">=</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>realpath(self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>))
        <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isfile(destination):
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>select_file(destination)
            <span style="color:#66d9ef">return</span>
    <span style="color:#66d9ef">else</span>:
        destination <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)

    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> destination:
        destination <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">~</span><span style="color:#e6db74">&#39;</span>

    <span style="color:#66d9ef">if</span> destination <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-</span><span style="color:#e6db74">&#39;</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>enter_bookmark(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">`</span><span style="color:#e6db74">&#39;</span>)
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>cd(destination)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#f92672">import</span> os
    <span style="color:#f92672">from</span> os.path <span style="color:#f92672">import</span> dirname, basename, expanduser, join

    cwd <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>path
    rel_dest <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)

    bookmarks <span style="color:#f92672">=</span> [v<span style="color:#f92672">.</span>path <span style="color:#66d9ef">for</span> v <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>bookmarks<span style="color:#f92672">.</span>dct<span style="color:#f92672">.</span>values()
            <span style="color:#66d9ef">if</span> rel_dest <span style="color:#f92672">in</span> v<span style="color:#f92672">.</span>path ]

    <span style="color:#75715e"># expand the tilde into the user directory</span>
    <span style="color:#66d9ef">if</span> rel_dest<span style="color:#f92672">.</span>startswith(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">~</span><span style="color:#e6db74">&#39;</span>):
        rel_dest <span style="color:#f92672">=</span> expanduser(rel_dest)

    <span style="color:#75715e"># define some shortcuts</span>
    abs_dest <span style="color:#f92672">=</span> join(cwd, rel_dest)
    abs_dirname <span style="color:#f92672">=</span> dirname(abs_dest)
    rel_basename <span style="color:#f92672">=</span> basename(rel_dest)
    rel_dirname <span style="color:#f92672">=</span> dirname(rel_dest)

    <span style="color:#66d9ef">try</span>:
        <span style="color:#75715e"># are we at the end of a directory?</span>
        <span style="color:#66d9ef">if</span> rel_dest<span style="color:#f92672">.</span>endswith(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">/</span><span style="color:#e6db74">&#39;</span>) <span style="color:#f92672">or</span> rel_dest <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">&#39;</span>:
            _, dirnames, _ <span style="color:#f92672">=</span> next(os<span style="color:#f92672">.</span>walk(abs_dest))

        <span style="color:#75715e"># are we in the middle of the filename?</span>
        <span style="color:#66d9ef">else</span>:
            _, dirnames, _ <span style="color:#f92672">=</span> next(os<span style="color:#f92672">.</span>walk(abs_dirname))
            dirnames <span style="color:#f92672">=</span> [dn <span style="color:#66d9ef">for</span> dn <span style="color:#f92672">in</span> dirnames \
                    <span style="color:#66d9ef">if</span> dn<span style="color:#f92672">.</span>startswith(rel_basename)]
    <span style="color:#66d9ef">except</span> (<span style="color:#a6e22e">OSError</span>, <span style="color:#a6e22e">StopIteration</span>):
        <span style="color:#75715e"># os.walk found nothing</span>
        <span style="color:#66d9ef">pass</span>
    <span style="color:#66d9ef">else</span>:
        dirnames<span style="color:#f92672">.</span>sort()
        <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>settings<span style="color:#f92672">.</span>cd_bookmarks:
            dirnames <span style="color:#f92672">=</span> bookmarks <span style="color:#f92672">+</span> dirnames

        <span style="color:#75715e"># no results, return None</span>
        <span style="color:#66d9ef">if</span> len(dirnames) <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>:
            <span style="color:#66d9ef">return</span>

        <span style="color:#75715e"># one result. since it must be a directory, append a slash.</span>
        <span style="color:#66d9ef">if</span> len(dirnames) <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>:
            <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>start(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span> join(rel_dirname, dirnames[<span style="color:#ae81ff">0</span>]) <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">/</span><span style="color:#e6db74">&#39;</span>

        <span style="color:#75715e"># more than one result. append no slash, so the user can</span>
        <span style="color:#75715e"># manually type in the slash to advance into that directory</span>
        <span style="color:#66d9ef">return</span> (self<span style="color:#f92672">.</span>start(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">+</span> join(rel_dirname, dirname) <span style="color:#66d9ef">for</span> dirname <span style="color:#f92672">in</span> dirnames)

class chain(Command): """:chain <command1>; <command2>; … Calls multiple commands at once, separated by semicolons. """ def execute(self): for command in self.rest(1).split(";"): self.fm.execute_console(command)

class shell(Command): escape_macros_for_shell = True

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">and</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)[<span style="color:#ae81ff">0</span>] <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-</span><span style="color:#e6db74">&#39;</span>:
        flags <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)[<span style="color:#ae81ff">1</span>:]
        command <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">2</span>)
    <span style="color:#66d9ef">else</span>:
        flags <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">&#39;</span>
        command <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)

    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> command <span style="color:#f92672">and</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">p</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">in</span> flags:
        command <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">cat </span><span style="color:#e6db74">%f</span><span style="color:#e6db74">&#39;</span>
    <span style="color:#66d9ef">if</span> command:
        <span style="color:#66d9ef">if</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">%</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">in</span> command:
            command <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>substitute_macros(command, escape<span style="color:#f92672">=</span>True)
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>execute_command(command, flags<span style="color:#f92672">=</span>flags)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#f92672">from</span> ranger.ext.get_executables <span style="color:#f92672">import</span> get_executables
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">and</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)[<span style="color:#ae81ff">0</span>] <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-</span><span style="color:#e6db74">&#39;</span>:
        command <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">2</span>)
    <span style="color:#66d9ef">else</span>:
        command <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
    start <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>line[<span style="color:#ae81ff">0</span>:len(self<span style="color:#f92672">.</span>line) <span style="color:#f92672">-</span> len(command)]

    <span style="color:#66d9ef">try</span>:
        position_of_last_space <span style="color:#f92672">=</span> command<span style="color:#f92672">.</span>rindex(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#34;</span>)
    <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">ValueError</span>:
        <span style="color:#66d9ef">return</span> (start <span style="color:#f92672">+</span> program <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#39;</span> <span style="color:#66d9ef">for</span> program \
                <span style="color:#f92672">in</span> get_executables() <span style="color:#66d9ef">if</span> program<span style="color:#f92672">.</span>startswith(command))
    <span style="color:#66d9ef">if</span> position_of_last_space <span style="color:#f92672">==</span> len(command) <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>:
        selection <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()
        <span style="color:#66d9ef">if</span> len(selection) <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>:
            <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>line <span style="color:#f92672">+</span> selection[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">.</span>shell_escaped_basename <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#39;</span>
        <span style="color:#66d9ef">else</span>:
            <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>line <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#39;</span>
    <span style="color:#66d9ef">else</span>:
        before_word, start_of_word <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>line<span style="color:#f92672">.</span>rsplit(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#39;</span>, <span style="color:#ae81ff">1</span>)
        <span style="color:#66d9ef">return</span> (before_word <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">+</span> file<span style="color:#f92672">.</span>shell_escaped_basename \
                <span style="color:#66d9ef">for</span> file <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>files \
                <span style="color:#66d9ef">if</span> file<span style="color:#f92672">.</span>shell_escaped_basename<span style="color:#f92672">.</span>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)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_tab_through_executables()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_get_app_flags_mode</span>(self, string):
    <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;&#34;&#34;</span><span style="color:#e6db74">Extracts the application, flags and mode from a string.</span><span style="color:#e6db74">

examples: "mplayer f 1" => ("mplayer", "f", 1) "aunpack 4" => ("aunpack", "", 4) "p" => ("", "p", 0) "" => None """

    app <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">&#39;</span>
    flags <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">&#39;</span>
    mode <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
    split <span style="color:#f92672">=</span> string<span style="color:#f92672">.</span>split()

    <span style="color:#66d9ef">if</span> len(split) <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>:
        <span style="color:#66d9ef">pass</span>

    <span style="color:#66d9ef">elif</span> len(split) <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>:
        part <span style="color:#f92672">=</span> split[<span style="color:#ae81ff">0</span>]
        <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_app(part):
            app <span style="color:#f92672">=</span> part
        <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_flags(part):
            flags <span style="color:#f92672">=</span> part
        <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_mode(part):
            mode <span style="color:#f92672">=</span> part

    <span style="color:#66d9ef">elif</span> len(split) <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span>:
        part0 <span style="color:#f92672">=</span> split[<span style="color:#ae81ff">0</span>]
        part1 <span style="color:#f92672">=</span> split[<span style="color:#ae81ff">1</span>]

        <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_app(part0):
            app <span style="color:#f92672">=</span> part0
            <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_flags(part1):
                flags <span style="color:#f92672">=</span> part1
            <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_mode(part1):
                mode <span style="color:#f92672">=</span> part1
        <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_flags(part0):
            flags <span style="color:#f92672">=</span> part0
            <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_mode(part1):
                mode <span style="color:#f92672">=</span> part1
        <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_mode(part0):
            mode <span style="color:#f92672">=</span> part0
            <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_flags(part1):
                flags <span style="color:#f92672">=</span> part1

    <span style="color:#66d9ef">elif</span> len(split) <span style="color:#f92672">&gt;</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">3</span>:
        part0 <span style="color:#f92672">=</span> split[<span style="color:#ae81ff">0</span>]
        part1 <span style="color:#f92672">=</span> split[<span style="color:#ae81ff">1</span>]
        part2 <span style="color:#f92672">=</span> split[<span style="color:#ae81ff">2</span>]

        <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_app(part0):
            app <span style="color:#f92672">=</span> part0
            <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_flags(part1):
                flags <span style="color:#f92672">=</span> part1
                <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_mode(part2):
                    mode <span style="color:#f92672">=</span> part2
            <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_mode(part1):
                mode <span style="color:#f92672">=</span> part1
                <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_flags(part2):
                    flags <span style="color:#f92672">=</span> part2
        <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_flags(part0):
            flags <span style="color:#f92672">=</span> part0
            <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_mode(part1):
                mode <span style="color:#f92672">=</span> part1
        <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>_is_mode(part0):
            mode <span style="color:#f92672">=</span> part0
            <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_is_flags(part1):
                flags <span style="color:#f92672">=</span> part1

    <span style="color:#66d9ef">return</span> app, flags, int(mode)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_is_app</span>(self, arg):
    <span style="color:#66d9ef">return</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>_is_flags(arg) <span style="color:#f92672">and</span> <span style="color:#f92672">not</span> arg<span style="color:#f92672">.</span>isdigit()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_is_flags</span>(self, arg):
    <span style="color:#f92672">from</span> ranger.core.runner <span style="color:#f92672">import</span> ALLOWED_FLAGS
    <span style="color:#66d9ef">return</span> all(x <span style="color:#f92672">in</span> ALLOWED_FLAGS <span style="color:#66d9ef">for</span> x <span style="color:#f92672">in</span> arg)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_is_mode</span>(self, arg):
    <span style="color:#66d9ef">return</span> all(x <span style="color:#f92672">in</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">0123456789</span><span style="color:#e6db74">&#39;</span> <span style="color:#66d9ef">for</span> x <span style="color:#f92672">in</span> arg)

class set_(Command): """:set <option name>=<python expression> Gives an option a new value. """ name = 'set' # don't override the builtin set class def execute(self): name = self.arg(1) name, value, _ = self.parse_setting_line() self.fm.set_option_from_string(name, value)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#f92672">from</span> ranger.gui.colorscheme <span style="color:#f92672">import</span> get_all_colorschemes
    name, value, name_done <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>parse_setting_line()
    settings <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>settings
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> name:
        <span style="color:#66d9ef">return</span> sorted(self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> setting <span style="color:#66d9ef">for</span> setting <span style="color:#f92672">in</span> settings)
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> value <span style="color:#f92672">and</span> <span style="color:#f92672">not</span> name_done:
        <span style="color:#66d9ef">return</span> (self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> setting <span style="color:#66d9ef">for</span> setting <span style="color:#f92672">in</span> settings \
                <span style="color:#66d9ef">if</span> setting<span style="color:#f92672">.</span>startswith(name))
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> value:
        <span style="color:#75715e"># Cycle through colorschemes when name, but no value is specified</span>
        <span style="color:#66d9ef">if</span> name <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">colorscheme</span><span style="color:#e6db74">&#34;</span>:
            <span style="color:#66d9ef">return</span> (self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> colorscheme <span style="color:#66d9ef">for</span> colorscheme \
                    <span style="color:#f92672">in</span> get_all_colorschemes())
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> str(settings[name])
    <span style="color:#66d9ef">if</span> bool <span style="color:#f92672">in</span> settings<span style="color:#f92672">.</span>types_of(name):
        <span style="color:#66d9ef">if</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">true</span><span style="color:#e6db74">&#39;</span><span style="color:#f92672">.</span>startswith(value<span style="color:#f92672">.</span>lower()):
            <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">True</span><span style="color:#e6db74">&#39;</span>
        <span style="color:#66d9ef">if</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">false</span><span style="color:#e6db74">&#39;</span><span style="color:#f92672">.</span>startswith(value<span style="color:#f92672">.</span>lower()):
            <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">False</span><span style="color:#e6db74">&#39;</span>
    <span style="color:#75715e"># Tab complete colorscheme values if incomplete value is present</span>
    <span style="color:#66d9ef">if</span> name <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">colorscheme</span><span style="color:#e6db74">&#34;</span>:
        <span style="color:#66d9ef">return</span> (self<span style="color:#f92672">.</span>firstpart <span style="color:#f92672">+</span> colorscheme <span style="color:#66d9ef">for</span> colorscheme \
                <span style="color:#f92672">in</span> get_all_colorschemes() <span style="color:#66d9ef">if</span> colorscheme<span style="color:#f92672">.</span>startswith(value))

class setlocal(set_): """:setlocal path=<python string> <option name>=<python expression> Gives an option a new value. """ PATH_RE = re.compile(r'^</span>s*path="?(.*?)"?</span>s*$') def execute(self): import os.path match = self.PATH_RE.match(self.arg(1)) if match: path = os.path.normpath(os.path.expanduser(match.group(1))) self.shift() elif self.fm.thisdir: path = self.fm.thisdir.path else: path = None

    <span style="color:#66d9ef">if</span> path:
        name <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)
        name, value, _ <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>parse_setting_line()
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>set_option_from_string(name, value, localpath<span style="color:#f92672">=</span>path)

class setintag(setlocal): """:setintag <tag or tags> <option name>=<option value> Sets an option for directories that are tagged with a specific tag. """ def execute(self): tags = self.arg(1) self.shift() name, value, _ = self.parse_setting_line() self.fm.set_option_from_string(name, value, tags=tags)

class default_linemode(Command): def execute(self): import re from ranger.container.fsobject import FileSystemObject

    <span style="color:#66d9ef">if</span> len(self<span style="color:#f92672">.</span>args) <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">2</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Usage: default_linemode [path=&lt;regexp&gt; | tag=&lt;tag(s)&gt;] &lt;linemode&gt;</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)

    <span style="color:#75715e"># Extract options like &#34;path=...&#34; or &#34;tag=...&#34; from the command line</span>
    arg1 <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)
    method <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">always</span><span style="color:#e6db74">&#34;</span>
    argument <span style="color:#f92672">=</span> None
    <span style="color:#66d9ef">if</span> arg1<span style="color:#f92672">.</span>startswith(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">path=</span><span style="color:#e6db74">&#34;</span>):
        method <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">path</span><span style="color:#e6db74">&#34;</span>
        argument <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(arg1[<span style="color:#ae81ff">5</span>:])
        self<span style="color:#f92672">.</span>shift()
    <span style="color:#66d9ef">elif</span> arg1<span style="color:#f92672">.</span>startswith(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">tag=</span><span style="color:#e6db74">&#34;</span>):
        method <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">tag</span><span style="color:#e6db74">&#34;</span>
        argument <span style="color:#f92672">=</span> arg1[<span style="color:#ae81ff">4</span>:]
        self<span style="color:#f92672">.</span>shift()

    <span style="color:#75715e"># Extract and validate the line mode from the command line</span>
    linemode <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
    <span style="color:#66d9ef">if</span> linemode <span style="color:#f92672">not</span> <span style="color:#f92672">in</span> FileSystemObject<span style="color:#f92672">.</span>linemode_dict:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Invalid linemode: </span><span style="color:#e6db74">%s</span><span style="color:#e6db74">; should be </span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span>
                (linemode, <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">/</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(FileSystemObject<span style="color:#f92672">.</span>linemode_dict)), bad<span style="color:#f92672">=</span>True)

    <span style="color:#75715e"># Add the prepared entry to the fm.default_linemodes</span>
    entry <span style="color:#f92672">=</span> [method, argument, linemode]
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>default_linemodes<span style="color:#f92672">.</span>appendleft(entry)

    <span style="color:#75715e"># Redraw the columns</span>
    <span style="color:#66d9ef">if</span> hasattr(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui, <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">browser</span><span style="color:#e6db74">&#34;</span>):
        <span style="color:#66d9ef">for</span> col <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>browser<span style="color:#f92672">.</span>columns:
            col<span style="color:#f92672">.</span>need_redraw <span style="color:#f92672">=</span> True

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    mode <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)
    <span style="color:#66d9ef">return</span> (self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">0</span>) <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">+</span> linemode
            <span style="color:#66d9ef">for</span> linemode <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>linemode_dict<span style="color:#f92672">.</span>keys()
            <span style="color:#66d9ef">if</span> linemode<span style="color:#f92672">.</span>startswith(self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)))

class quit(Command): """:quit Closes the current tab. If there is only one tab, quit the program. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> len(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tabs) <span style="color:#f92672">&lt;</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>exit()
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tab_close()

class quitall(Command): """:quitall Quits the program immediately. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>exit()

class quit_bang(quitall): """:quit! Quits the program immediately. """ name = 'quit!' allow_abbrev = False

class terminal(Command): """:terminal Spawns an "x-terminal-emulator" starting in the current directory. """ def execute(self): import os from ranger.ext.get_executables import get_executables command = os.environ.get('TERMCMD', os.environ.get('TERM')) if command not in get_executables(): command = 'x-terminal-emulator' if command not in get_executables(): command = 'xterm' self.fm.run(command, flags='f')

class delete(Command): """:delete Tries to delete the selection. "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 delete non-empty directories or multiple marked files, it will require a confirmation. """

allow_abbrev <span style="color:#f92672">=</span> False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#f92672">import</span> os
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>):
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Error: delete takes no arguments! It deletes </span><span style="color:#e6db74">&#34;</span>
                <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">the selected file(s).</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)
        <span style="color:#66d9ef">return</span>

    cwd <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir
    cf <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> cwd <span style="color:#f92672">or</span> <span style="color:#f92672">not</span> cf:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Error: no file selected for deletion!</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)
        <span style="color:#66d9ef">return</span>

    confirm <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>settings<span style="color:#f92672">.</span>confirm_on_delete
    many_files <span style="color:#f92672">=</span> (cwd<span style="color:#f92672">.</span>marked_items <span style="color:#f92672">or</span> (cf<span style="color:#f92672">.</span>is_directory <span style="color:#f92672">and</span> <span style="color:#f92672">not</span> cf<span style="color:#f92672">.</span>is_link \
            <span style="color:#f92672">and</span> len(os<span style="color:#f92672">.</span>listdir(cf<span style="color:#f92672">.</span>path)) <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>))

    <span style="color:#66d9ef">if</span> confirm <span style="color:#f92672">!=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">never</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">and</span> (confirm <span style="color:#f92672">!=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">multiple</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">or</span> many_files):
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>console<span style="color:#f92672">.</span>ask(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Confirm deletion of: </span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> (y/N)</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span>
            <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">, </span><span style="color:#e6db74">&#39;</span><span style="color:#f92672">.</span>join(f<span style="color:#f92672">.</span>relative_path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()),
            self<span style="color:#f92672">.</span>_question_callback, (<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">n</span><span style="color:#e6db74">&#39;</span>, <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">N</span><span style="color:#e6db74">&#39;</span>, <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">y</span><span style="color:#e6db74">&#39;</span>, <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">Y</span><span style="color:#e6db74">&#39;</span>))
    <span style="color:#66d9ef">else</span>:
        <span style="color:#75715e"># no need for a confirmation, just delete</span>
        <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags:
            <span style="color:#66d9ef">if</span> str(f)<span style="color:#f92672">.</span>startswith(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path):
                self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>remove(f)
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>delete()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_question_callback</span>(self, answer):
    <span style="color:#66d9ef">if</span> answer <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">y</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">or</span> answer <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">Y</span><span style="color:#e6db74">&#39;</span>:
        <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags:
            <span style="color:#66d9ef">if</span> str(f)<span style="color:#f92672">.</span>startswith(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path):
                self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>remove(f)
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>delete()

class mark_tag(Command): """:mark_tag [<tags>] Mark all tags that are tagged with either of the given tags. When leaving out the tag argument, all tagged files are marked. """ do_mark = True

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    cwd <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir
    tags <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)<span style="color:#f92672">.</span>replace(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#34;</span>,<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">&#34;</span>)
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags:
        <span style="color:#66d9ef">return</span>
    <span style="color:#66d9ef">for</span> fileobj <span style="color:#f92672">in</span> cwd<span style="color:#f92672">.</span>files:
        <span style="color:#66d9ef">try</span>:
            tag <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags[fileobj<span style="color:#f92672">.</span>realpath]
        <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">KeyError</span>:
            <span style="color:#66d9ef">continue</span>
        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> tags <span style="color:#f92672">or</span> tag <span style="color:#f92672">in</span> tags:
            cwd<span style="color:#f92672">.</span>mark_item(fileobj, val<span style="color:#f92672">=</span>self<span style="color:#f92672">.</span>do_mark)
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>status<span style="color:#f92672">.</span>need_redraw <span style="color:#f92672">=</span> True
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>need_redraw <span style="color:#f92672">=</span> True

class console(Command): """:console <command> Open the console with the given command. """ def execute(self): position = None if self.arg(1)[0:2] == '-p': try: position = int(self.arg(1)[2:]) self.shift() except: pass self.fm.open_console(self.rest(1), position=position)

class load_copy_buffer(Command): """:load_copy_buffer Load the copy buffer from confdir/copy_buffer """ copy_buffer_filename = 'copy_buffer' def execute(self): from ranger.container.file import File from os.path import exists try: fname = self.fm.confpath(self.copy_buffer_filename) f = open(fname, 'r') except: return self.fm.notify("Cannot open %s" %
(fname or self.copy_buffer_filename), bad=True) self.fm.copy_buffer = set(File(g)
for g in f.read().split("\n") if exists(g)) f.close() self.fm.ui.redraw_main_column()

class save_copy_buffer(Command): """:save_copy_buffer Save the copy buffer to confdir/copy_buffer """ copy_buffer_filename = 'copy_buffer' def execute(self): fname = None try: fname = self.fm.confpath(self.copy_buffer_filename) f = open(fname, 'w') except: return self.fm.notify("Cannot open %s" %
(fname or self.copy_buffer_filename), bad=True) f.write("\n".join(f.path for f in self.fm.copy_buffer)) f.close()

class unmark_tag(mark_tag): """:unmark_tag [<tags>] Unmark all tags that are tagged with either of the given tags. When leaving out the tag argument, all tagged files are unmarked. """ do_mark = False

class mkdir(Command): """:mkdir <dirname> Creates a directory with the name <dirname>. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#f92672">from</span> os.path <span style="color:#f92672">import</span> join, expanduser, lexists
    <span style="color:#f92672">from</span> os <span style="color:#f92672">import</span> makedirs

    dirname <span style="color:#f92672">=</span> join(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>path, expanduser(self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)))
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> lexists(dirname):
        makedirs(dirname)
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">file/directory exists!</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_tab_directory_content()

class touch(Command): """:touch <fname> Creates a file with the name <fname>. """

resolve_macros <span style="color:#f92672">=</span> False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#f92672">from</span> os.path <span style="color:#f92672">import</span> join, expanduser, lexists

    fname <span style="color:#f92672">=</span> join(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>path, expanduser(self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)))
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> lexists(fname):
        open(fname, <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">a</span><span style="color:#e6db74">&#39;</span>)<span style="color:#f92672">.</span>close()
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">file/directory exists!</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_tab_directory_content()

class edit(Command): """:edit <filename> Opens the specified file in vim """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>):
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>edit_file(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path)
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>edit_file(self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>))

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_tab_directory_content()

class eval_(Command): """:eval [-q] <python code> Evaluates the python code. fm</span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74"> is a reference to the FM instance.</span><span style="color:#e6db74"> </span><span style="color:#e6db74"></span><span style="color:#e6db74"> To display text, use the function p'. Examples: :eval fm :eval len(fm.directories) :eval p("Hello World!") """ name = 'eval' resolve_macros = False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-q</span><span style="color:#e6db74">&#39;</span>:
        code <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">2</span>)
        quiet <span style="color:#f92672">=</span> True
    <span style="color:#66d9ef">else</span>:
        code <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
        quiet <span style="color:#f92672">=</span> False
    <span style="color:#f92672">import</span> ranger
    <span style="color:#66d9ef">global</span> cmd, fm, p, quantifier
    fm <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm
    cmd <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>execute_console
    p <span style="color:#f92672">=</span> fm<span style="color:#f92672">.</span>notify
    quantifier <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>quantifier
    <span style="color:#66d9ef">try</span>:
        <span style="color:#66d9ef">try</span>:
            result <span style="color:#f92672">=</span> eval(code)
        <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">SyntaxError</span>:
            <span style="color:#66d9ef">exec</span>(code)
        <span style="color:#66d9ef">else</span>:
            <span style="color:#66d9ef">if</span> result <span style="color:#f92672">and</span> <span style="color:#f92672">not</span> quiet:
                p(result)
    <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">Exception</span> <span style="color:#66d9ef">as</span> err:
        p(err)

class rename(Command): """:rename <newname> Changes the name of the currently highlighted file to <newname> """

resolve_macros <span style="color:#f92672">=</span> False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#f92672">from</span> ranger.container.file <span style="color:#f92672">import</span> File
    <span style="color:#f92672">from</span> os <span style="color:#f92672">import</span> access

    new_name <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)

    tagged <span style="color:#f92672">=</span> {}
    old_name <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>relative_path
    <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags:
        <span style="color:#66d9ef">if</span> str(f)<span style="color:#f92672">.</span>startswith(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path):
            tagged[f] <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags[f]
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>remove(f)

    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> new_name:
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">Syntax: rename &lt;newname&gt;</span><span style="color:#e6db74">&#39;</span>, bad<span style="color:#f92672">=</span>True)

    <span style="color:#66d9ef">if</span> new_name <span style="color:#f92672">==</span> old_name:
        <span style="color:#66d9ef">return</span>

    <span style="color:#66d9ef">if</span> access(new_name, os<span style="color:#f92672">.</span>F_OK):
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Can</span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">t rename: file already exists!</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)

    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>rename(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile, new_name):
        f <span style="color:#f92672">=</span> File(new_name)
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>pointed_obj <span style="color:#f92672">=</span> f
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile <span style="color:#f92672">=</span> f
        <span style="color:#66d9ef">for</span> t <span style="color:#f92672">in</span> tagged:
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags[t<span style="color:#f92672">.</span>replace(old_name,new_name)] <span style="color:#f92672">=</span> tagged[t]
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>dump()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_tab_directory_content()

class rename_append(Command): """:rename_append Creates an open_console for the rename command, automatically placing the cursor before the file extension. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    cf <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile
    <span style="color:#66d9ef">if</span> cf<span style="color:#f92672">.</span>relative_path<span style="color:#f92672">.</span>find(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">.</span><span style="color:#e6db74">&#39;</span>) <span style="color:#f92672">!=</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">and</span> cf<span style="color:#f92672">.</span>relative_path<span style="color:#f92672">.</span>rfind(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">.</span><span style="color:#e6db74">&#39;</span>) <span style="color:#f92672">!=</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span> <span style="color:#f92672">and</span> <span style="color:#f92672">not</span> cf<span style="color:#f92672">.</span>is_directory:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>open_console(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">rename </span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">+</span> cf<span style="color:#f92672">.</span>relative_path, position<span style="color:#f92672">=</span>(<span style="color:#ae81ff">7</span> <span style="color:#f92672">+</span> cf<span style="color:#f92672">.</span>relative_path<span style="color:#f92672">.</span>rfind(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">.</span><span style="color:#e6db74">&#39;</span>)))
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>open_console(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">rename </span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">+</span> cf<span style="color:#f92672">.</span>relative_path)

class chmod(Command): """:chmod <octal number> Sets the permissions of the selection to the octal number. The octal number is between 0 and 777. The digits specify the permissions for the user, the group and others. A 1 permits execution, a 2 permits writing, a 4 permits reading. Add those numbers to combine them. So a 7 permits everything. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    mode <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> mode:
        mode <span style="color:#f92672">=</span> str(self<span style="color:#f92672">.</span>quantifier)

    <span style="color:#66d9ef">try</span>:
        mode <span style="color:#f92672">=</span> int(mode, <span style="color:#ae81ff">8</span>)
        <span style="color:#66d9ef">if</span> mode <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">or</span> mode <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>o777:
            <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">ValueError</span>
    <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">ValueError</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Need an octal number between 0 and 777!</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)
        <span style="color:#66d9ef">return</span>

    <span style="color:#66d9ef">for</span> file <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection():
        <span style="color:#66d9ef">try</span>:
            os<span style="color:#f92672">.</span>chmod(file<span style="color:#f92672">.</span>path, mode)
        <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">Exception</span> <span style="color:#66d9ef">as</span> ex:
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(ex)

    <span style="color:#66d9ef">try</span>:
        <span style="color:#75715e"># reloading directory.  maybe its better to reload the selected</span>
        <span style="color:#75715e"># files only.</span>
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>load_content()
    <span style="color:#66d9ef">except</span>:
        <span style="color:#66d9ef">pass</span>

class bulkrename(Command): """:bulkrename This command opens a list of selected files in an external editor. After you edit and save the file, it will generate a shell script which does bulk renaming according to the changes you did in the file. This shell script is opened in an editor for you to review. After you close it, it will be executed. """ def execute(self): import sys import tempfile from ranger.container.file import File from ranger.ext.shell_escape import shell_escape as esc py3 = sys.version_info[0] >= 3

    <span style="color:#75715e"># Create and edit the file list</span>
    filenames <span style="color:#f92672">=</span> [f<span style="color:#f92672">.</span>relative_path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()]
    listfile <span style="color:#f92672">=</span> tempfile<span style="color:#f92672">.</span>NamedTemporaryFile(delete<span style="color:#f92672">=</span>False)
    listpath <span style="color:#f92672">=</span> listfile<span style="color:#f92672">.</span>name

    <span style="color:#66d9ef">if</span> py3:
        listfile<span style="color:#f92672">.</span>write(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(filenames)<span style="color:#f92672">.</span>encode(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">utf-8</span><span style="color:#e6db74">&#34;</span>))
    <span style="color:#66d9ef">else</span>:
        listfile<span style="color:#f92672">.</span>write(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(filenames))
    listfile<span style="color:#f92672">.</span>close()
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>execute_file([File(listpath)], app<span style="color:#f92672">=</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">editor</span><span style="color:#e6db74">&#39;</span>)
    listfile <span style="color:#f92672">=</span> open(listpath, <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">r</span><span style="color:#e6db74">&#39;</span>)
    new_filenames <span style="color:#f92672">=</span> listfile<span style="color:#f92672">.</span>read()<span style="color:#f92672">.</span>split(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>)
    listfile<span style="color:#f92672">.</span>close()
    os<span style="color:#f92672">.</span>unlink(listpath)
    <span style="color:#66d9ef">if</span> all(a <span style="color:#f92672">==</span> b <span style="color:#66d9ef">for</span> a, b <span style="color:#f92672">in</span> zip(filenames, new_filenames)):
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">No renaming to be done!</span><span style="color:#e6db74">&#34;</span>)
        <span style="color:#66d9ef">return</span>

    <span style="color:#75715e"># Generate script</span>
    cmdfile <span style="color:#f92672">=</span> tempfile<span style="color:#f92672">.</span>NamedTemporaryFile()
    script_lines <span style="color:#f92672">=</span> []
    script_lines<span style="color:#f92672">.</span>append(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"># This file will be executed when you close the editor.</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>)
    script_lines<span style="color:#f92672">.</span>append(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"># Please double-check everything, clear the file to abort.</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>)
    script_lines<span style="color:#f92672">.</span>extend(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">mv -vi -- </span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> </span><span style="color:#e6db74">%s</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> (esc(old), esc(new)) \
            <span style="color:#66d9ef">for</span> old, new <span style="color:#f92672">in</span> zip(filenames, new_filenames) <span style="color:#66d9ef">if</span> old <span style="color:#f92672">!=</span> new)
    script_content <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(script_lines)
    <span style="color:#66d9ef">if</span> py3:
        cmdfile<span style="color:#f92672">.</span>write(script_content<span style="color:#f92672">.</span>encode(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">utf-8</span><span style="color:#e6db74">&#34;</span>))
    <span style="color:#66d9ef">else</span>:
        cmdfile<span style="color:#f92672">.</span>write(script_content)
    cmdfile<span style="color:#f92672">.</span>flush()

    <span style="color:#75715e"># Open the script and let the user review it, then check if the script</span>
    <span style="color:#75715e"># was modified by the user</span>
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>execute_file([File(cmdfile<span style="color:#f92672">.</span>name)], app<span style="color:#f92672">=</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">editor</span><span style="color:#e6db74">&#39;</span>)
    cmdfile<span style="color:#f92672">.</span>seek(<span style="color:#ae81ff">0</span>)
    script_was_edited <span style="color:#f92672">=</span> (script_content <span style="color:#f92672">!=</span> cmdfile<span style="color:#f92672">.</span>read())

    <span style="color:#75715e"># Do the renaming</span>
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>run([<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">/bin/sh</span><span style="color:#e6db74">&#39;</span>, cmdfile<span style="color:#f92672">.</span>name], flags<span style="color:#f92672">=</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">w</span><span style="color:#e6db74">&#39;</span>)
    cmdfile<span style="color:#f92672">.</span>close()

    <span style="color:#75715e"># Retag the files, but only if the script wasn&#39;t changed during review,</span>
    <span style="color:#75715e"># because only then we know which are the source and destination files.</span>
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> script_was_edited:
        tags_changed <span style="color:#f92672">=</span> False
        <span style="color:#66d9ef">for</span> old, new <span style="color:#f92672">in</span> zip(filenames, new_filenames):
            <span style="color:#66d9ef">if</span> old <span style="color:#f92672">!=</span> new:
                oldpath <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>path <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">/</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">+</span> old
                newpath <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>path <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">/</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">+</span> new
                <span style="color:#66d9ef">if</span> oldpath <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags:
                    old_tag <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags[oldpath]
                    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>remove(oldpath)
                    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>tags[newpath] <span style="color:#f92672">=</span> old_tag
                    tags_changed <span style="color:#f92672">=</span> True
        <span style="color:#66d9ef">if</span> tags_changed:
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>tags<span style="color:#f92672">.</span>dump()
    <span style="color:#66d9ef">else</span>:
        fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">files have not been retagged</span><span style="color:#e6db74">&#34;</span>)

class relink(Command): """:relink <newpath> Changes the linked path of the currently highlighted symlink to <newpath> """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#f92672">from</span> ranger.container.file <span style="color:#f92672">import</span> File

    new_path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
    cf <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile

    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> new_path:
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">Syntax: relink &lt;newpath&gt;</span><span style="color:#e6db74">&#39;</span>, bad<span style="color:#f92672">=</span>True)

    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> cf<span style="color:#f92672">.</span>is_link:
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> is not a symlink!</span><span style="color:#e6db74">&#39;</span> <span style="color:#f92672">%</span> cf<span style="color:#f92672">.</span>relative_path, bad<span style="color:#f92672">=</span>True)

    <span style="color:#66d9ef">if</span> new_path <span style="color:#f92672">==</span> os<span style="color:#f92672">.</span>readlink(cf<span style="color:#f92672">.</span>path):
        <span style="color:#66d9ef">return</span>

    <span style="color:#66d9ef">try</span>:
        os<span style="color:#f92672">.</span>remove(cf<span style="color:#f92672">.</span>path)
        os<span style="color:#f92672">.</span>symlink(new_path, cf<span style="color:#f92672">.</span>path)
    <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">OSError</span> <span style="color:#66d9ef">as</span> err:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(err)

    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>reset()
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>pointed_obj <span style="color:#f92672">=</span> cf
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile <span style="color:#f92672">=</span> cf

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>):
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>line<span style="color:#f92672">+</span>os<span style="color:#f92672">.</span>readlink(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path)
    <span style="color:#66d9ef">else</span>:
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_tab_directory_content()

class help_(Command): """:help Display ranger's manual page. """ name = 'help' def execute(self): def callback(answer): if answer == "q": return elif answer == "m": self.fm.display_help() elif answer == "c": self.fm.dump_commands() elif answer == "k": self.fm.dump_keybindings() elif answer == "s": self.fm.dump_settings()

    c <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>console<span style="color:#f92672">.</span>ask(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">View [m]an page, [k]ey bindings,</span><span style="color:#e6db74">&#34;</span>
            <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"> [c]ommands or [s]ettings? (press q to abort)</span><span style="color:#e6db74">&#34;</span>, callback, list(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">mkcsq</span><span style="color:#e6db74">&#34;</span>) <span style="color:#f92672">+</span> [chr(<span style="color:#ae81ff">27</span>)])

class copymap(Command): """:copymap <keys> <newkeys1> [<newkeys2>…] Copies a "browser" keybinding from <keys> to <newkeys> """ context = 'browser'

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">or</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">2</span>):
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Not enough arguments</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)

    <span style="color:#66d9ef">for</span> arg <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>args[<span style="color:#ae81ff">2</span>:]:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>keymaps<span style="color:#f92672">.</span>copy(self<span style="color:#f92672">.</span>context, self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>), arg)

class copypmap(copymap): """:copypmap <keys> <newkeys1> [<newkeys2>…] Copies a "pager" keybinding from <keys> to <newkeys> """ context = 'pager'

class copycmap(copymap): """:copycmap <keys> <newkeys1> [<newkeys2>…] Copies a "console" keybinding from <keys> to <newkeys> """ context = 'console'

class copytmap(copymap): """:copycmap <keys> <newkeys1> [<newkeys2>…] Copies a "taskview" keybinding from <keys> to <newkeys> """ context = 'taskview'

class unmap(Command): """:unmap <keys> [<keys2>, …] Remove the given "browser" mappings """ context = 'browser'

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">for</span> arg <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>args[<span style="color:#ae81ff">1</span>:]:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>keymaps<span style="color:#f92672">.</span>unbind(self<span style="color:#f92672">.</span>context, arg)

class cunmap(unmap): """:cunmap <keys> [<keys2>, …] Remove the given "console" mappings """ context = 'browser'

class punmap(unmap): """:punmap <keys> [<keys2>, …] Remove the given "pager" mappings """ context = 'pager'

class tunmap(unmap): """:tunmap <keys> [<keys2>, …] Remove the given "taskview" mappings """ context = 'taskview'

class map_(Command): """:map <keysequence> <command> Maps a command to a keysequence in the "browser" context. Example: map j move down map J move down 10 """ name = 'map' context = 'browser' resolve_macros = False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">or</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">2</span>):
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Not enough arguments</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)

    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>keymaps<span style="color:#f92672">.</span>bind(self<span style="color:#f92672">.</span>context, self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>), self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">2</span>))

class cmap(map_): """:cmap <keysequence> <command> Maps a command to a keysequence in the "console" context. Example: cmap <ESC> console_close cmap <C-x> console_type test """ context = 'console'

class tmap(map_): """:tmap <keysequence> <command> Maps a command to a keysequence in the "taskview" context. """ context = 'taskview'

class pmap(map_): """:pmap <keysequence> <command> Maps a command to a keysequence in the "pager" context. """ context = 'pager'

class scout(Command): """:scout [-FLAGS] <pattern> Swiss army knife command for searching, traveling and filtering files. The command takes various flags as arguments which can be used to influence its behaviour: -a = automatically open a file on unambiguous match -e = open the selected file when pressing enter -f = filter files that match the current search pattern -g = interpret pattern as a glob pattern -i = ignore the letter case of the files -k = keep the console open when changing a directory with the command -l = letter skipping; e.g. allow "rdme" to match the file "readme" -m = mark the matching files after pressing enter -M = unmark the matching files after pressing enter -p = permanent filter: hide non-matching files after pressing enter -s = smart case; like -i unless pattern contains upper case letters -t = apply filter and search pattern as you type -v = inverts the match Multiple flags can be combined. For example, ":scout -gpt" would create a :filter-like command using globbing. """ AUTO_OPEN = 'a' OPEN_ON_ENTER = 'e' FILTER = 'f' SM_GLOB = 'g' IGNORE_CASE = 'i' KEEP_OPEN = 'k' SM_LETTERSKIP = 'l' MARK = 'm' UNMARK = 'M' PERM_FILTER = 'p' SM_REGEX = 'r' SMART_CASE = 's' AS_YOU_TYPE = 't' INVERT = 'v'

<span style="color:#66d9ef">def</span> __init__(self, <span style="color:#f92672">*</span>args, <span style="color:#f92672">*</span><span style="color:#f92672">*</span>kws):
    Command<span style="color:#f92672">.</span>__init__(self, <span style="color:#f92672">*</span>args, <span style="color:#f92672">*</span><span style="color:#f92672">*</span>kws)
    self<span style="color:#f92672">.</span>_regex <span style="color:#f92672">=</span> None
    self<span style="color:#f92672">.</span>flags, self<span style="color:#f92672">.</span>pattern <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>parse_flags()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    thisdir <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir
    flags   <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>flags
    pattern <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>pattern
    regex   <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>_build_regex()
    count   <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>_count(move<span style="color:#f92672">=</span>True)

    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>last_search <span style="color:#f92672">=</span> regex
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>set_search_method(order<span style="color:#f92672">=</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">search</span><span style="color:#e6db74">&#34;</span>)

    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>MARK <span style="color:#f92672">in</span> flags <span style="color:#f92672">or</span> self<span style="color:#f92672">.</span>UNMARK <span style="color:#f92672">in</span> flags:
        value <span style="color:#f92672">=</span> flags<span style="color:#f92672">.</span>find(self<span style="color:#f92672">.</span>MARK) <span style="color:#f92672">&gt;</span> flags<span style="color:#f92672">.</span>find(self<span style="color:#f92672">.</span>UNMARK)
        <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>FILTER <span style="color:#f92672">in</span> flags:
            <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> thisdir<span style="color:#f92672">.</span>files:
                thisdir<span style="color:#f92672">.</span>mark_item(f, value)
        <span style="color:#66d9ef">else</span>:
            <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> thisdir<span style="color:#f92672">.</span>files:
                <span style="color:#66d9ef">if</span> regex<span style="color:#f92672">.</span>search(f<span style="color:#f92672">.</span>relative_path):
                    thisdir<span style="color:#f92672">.</span>mark_item(f, value)

    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>PERM_FILTER <span style="color:#f92672">in</span> flags:
        thisdir<span style="color:#f92672">.</span>filter <span style="color:#f92672">=</span> regex <span style="color:#66d9ef">if</span> pattern <span style="color:#66d9ef">else</span> None

    <span style="color:#75715e"># clean up:</span>
    self<span style="color:#f92672">.</span>cancel()

    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>OPEN_ON_ENTER <span style="color:#f92672">in</span> flags <span style="color:#f92672">or</span> \
            self<span style="color:#f92672">.</span>AUTO_OPEN <span style="color:#f92672">in</span> flags <span style="color:#f92672">and</span> count <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>:
        <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(pattern):
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>cd(pattern)
        <span style="color:#66d9ef">else</span>:
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>move(right<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>)

    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>KEEP_OPEN <span style="color:#f92672">in</span> flags <span style="color:#f92672">and</span> thisdir <span style="color:#f92672">!=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir:
        <span style="color:#75715e"># reopen the console:</span>
        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> pattern:
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>open_console(self<span style="color:#f92672">.</span>line)
        <span style="color:#66d9ef">else</span>:
            self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>open_console(self<span style="color:#f92672">.</span>line[<span style="color:#ae81ff">0</span>:<span style="color:#f92672">-</span>len(pattern)])

    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>quickly_executed <span style="color:#f92672">and</span> thisdir <span style="color:#f92672">!=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir <span style="color:#f92672">and</span> pattern <span style="color:#f92672">!=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">..</span><span style="color:#e6db74">&#34;</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>block_input(<span style="color:#ae81ff">0.5</span>)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">cancel</span>(self):
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>temporary_filter <span style="color:#f92672">=</span> None
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>refilter()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">quick</span>(self):
    asyoutype <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>AS_YOU_TYPE <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>flags
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>FILTER <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>flags:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>temporary_filter <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>_build_regex()
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>PERM_FILTER <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>flags <span style="color:#f92672">and</span> asyoutype:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>filter <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>_build_regex()
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>FILTER <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>flags <span style="color:#f92672">or</span> self<span style="color:#f92672">.</span>PERM_FILTER <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>flags:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>refilter()
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_count(move<span style="color:#f92672">=</span>asyoutype) <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span> <span style="color:#f92672">and</span> self<span style="color:#f92672">.</span>AUTO_OPEN <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>flags:
        <span style="color:#66d9ef">return</span> True
    <span style="color:#66d9ef">return</span> False

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    self<span style="color:#f92672">.</span>_count(move<span style="color:#f92672">=</span>True, offset<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>)

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_build_regex</span>(self):
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>_regex <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> None:
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_regex

    frmat   <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#34;</span>
    flags   <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>flags
    pattern <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>pattern

    <span style="color:#66d9ef">if</span> pattern <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">.</span><span style="color:#e6db74">&#34;</span>:
        <span style="color:#66d9ef">return</span> re<span style="color:#f92672">.</span>compile(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">&#34;</span>)

    <span style="color:#75715e"># Handle carets at start and dollar signs at end separately</span>
    <span style="color:#66d9ef">if</span> pattern<span style="color:#f92672">.</span>startswith(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">^</span><span style="color:#e6db74">&#39;</span>):
        pattern <span style="color:#f92672">=</span> pattern[<span style="color:#ae81ff">1</span>:]
        frmat <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">^</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">+</span> frmat
    <span style="color:#66d9ef">if</span> pattern<span style="color:#f92672">.</span>endswith(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">$</span><span style="color:#e6db74">&#39;</span>):
        pattern <span style="color:#f92672">=</span> pattern[:<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>]
        frmat <span style="color:#f92672">+</span><span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">$</span><span style="color:#e6db74">&#34;</span>

    <span style="color:#75715e"># Apply one of the search methods</span>
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>SM_REGEX <span style="color:#f92672">in</span> flags:
        regex <span style="color:#f92672">=</span> pattern
    <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>SM_GLOB <span style="color:#f92672">in</span> flags:
        regex <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>escape(pattern)<span style="color:#f92672">.</span>replace(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\\</span><span style="color:#e6db74">*</span><span style="color:#e6db74">&#34;</span>, <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">.*</span><span style="color:#e6db74">&#34;</span>)<span style="color:#f92672">.</span>replace(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\\</span><span style="color:#e6db74">?</span><span style="color:#e6db74">&#34;</span>, <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">.</span><span style="color:#e6db74">&#34;</span>)
    <span style="color:#66d9ef">elif</span> self<span style="color:#f92672">.</span>SM_LETTERSKIP <span style="color:#f92672">in</span> flags:
        regex <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">.*</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join(re<span style="color:#f92672">.</span>escape(c) <span style="color:#66d9ef">for</span> c <span style="color:#f92672">in</span> pattern)
    <span style="color:#66d9ef">else</span>:
        regex <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>escape(pattern)

    regex <span style="color:#f92672">=</span> frmat <span style="color:#f92672">%</span> regex

    <span style="color:#75715e"># Invert regular expression if necessary</span>
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>INVERT <span style="color:#f92672">in</span> flags:
        regex <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">^(?:(?!</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">).)*$</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> regex

    <span style="color:#75715e"># Compile Regular Expression</span>
    options <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>LOCALE <span style="color:#f92672">|</span> re<span style="color:#f92672">.</span>UNICODE
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>IGNORE_CASE <span style="color:#f92672">in</span> flags <span style="color:#f92672">or</span> self<span style="color:#f92672">.</span>SMART_CASE <span style="color:#f92672">in</span> flags <span style="color:#f92672">and</span> \
            pattern<span style="color:#f92672">.</span>islower():
        options <span style="color:#f92672">|</span><span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>IGNORECASE
    <span style="color:#66d9ef">try</span>:
        self<span style="color:#f92672">.</span>_regex <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(regex, options)
    <span style="color:#66d9ef">except</span>:
        self<span style="color:#f92672">.</span>_regex <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">&#34;</span>)
    <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>_regex

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_count</span>(self, move<span style="color:#f92672">=</span>False, offset<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>):
    count   <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
    cwd     <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir
    pattern <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>pattern

    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> pattern:
        <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>
    <span style="color:#66d9ef">if</span> pattern <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">.</span><span style="color:#e6db74">&#39;</span>:
        <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>
    <span style="color:#66d9ef">if</span> pattern <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">..</span><span style="color:#e6db74">&#39;</span>:
        <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">1</span>

    deq <span style="color:#f92672">=</span> deque(cwd<span style="color:#f92672">.</span>files)
    deq<span style="color:#f92672">.</span>rotate(<span style="color:#f92672">-</span>cwd<span style="color:#f92672">.</span>pointer <span style="color:#f92672">-</span> offset)
    i <span style="color:#f92672">=</span> offset
    regex <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>_build_regex()
    <span style="color:#66d9ef">for</span> fsobj <span style="color:#f92672">in</span> deq:
        <span style="color:#66d9ef">if</span> regex<span style="color:#f92672">.</span>search(fsobj<span style="color:#f92672">.</span>relative_path):
            count <span style="color:#f92672">+</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
            <span style="color:#66d9ef">if</span> move <span style="color:#f92672">and</span> count <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>:
                cwd<span style="color:#f92672">.</span>move(to<span style="color:#f92672">=</span>(cwd<span style="color:#f92672">.</span>pointer <span style="color:#f92672">+</span> i) <span style="color:#f92672">%</span> len(cwd<span style="color:#f92672">.</span>files))
                self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile <span style="color:#f92672">=</span> cwd<span style="color:#f92672">.</span>pointed_obj
        <span style="color:#66d9ef">if</span> count <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">1</span>:
            <span style="color:#66d9ef">return</span> count
        i <span style="color:#f92672">+</span><span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>

    <span style="color:#66d9ef">return</span> count <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>

class filter_inode_type(Command): """ :filter_inode_type [dfl] Displays only the files of specified inode type. Parameters can be combined. d display directories f display files l display links """

FILTER_DIRS  <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">d</span><span style="color:#e6db74">&#39;</span>
FILTER_FILES <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">f</span><span style="color:#e6db74">&#39;</span>
FILTER_LINKS <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">l</span><span style="color:#e6db74">&#39;</span>

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>):
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>inode_type_filter <span style="color:#f92672">=</span> None
    <span style="color:#66d9ef">else</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>inode_type_filter <span style="color:#f92672">=</span> <span style="color:#66d9ef">lambda</span> file: (
                True <span style="color:#66d9ef">if</span> ((self<span style="color:#f92672">.</span>FILTER_DIRS  <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">and</span> file<span style="color:#f92672">.</span>is_directory) <span style="color:#f92672">or</span>
                         (self<span style="color:#f92672">.</span>FILTER_FILES <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">and</span> file<span style="color:#f92672">.</span>is_file <span style="color:#f92672">and</span> <span style="color:#f92672">not</span> file<span style="color:#f92672">.</span>is_link) <span style="color:#f92672">or</span>
                         (self<span style="color:#f92672">.</span>FILTER_LINKS <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>) <span style="color:#f92672">and</span> file<span style="color:#f92672">.</span>is_link)) <span style="color:#66d9ef">else</span> False)
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>refilter()

class grep(Command): """:grep <string> Looks for a string in all marked files or directories """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>):
        action <span style="color:#f92672">=</span> [<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">grep</span><span style="color:#e6db74">&#39;</span>, <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">--line-number</span><span style="color:#e6db74">&#39;</span>]
        action<span style="color:#f92672">.</span>extend([<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-e</span><span style="color:#e6db74">&#39;</span>, self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>), <span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">-r</span><span style="color:#e6db74">&#39;</span>])
        action<span style="color:#f92672">.</span>extend(f<span style="color:#f92672">.</span>path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection())
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>execute_command(action, flags<span style="color:#f92672">=</span><span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">p</span><span style="color:#e6db74">&#39;</span>)

# Version control commands # ——————————– class stage(Command): """ :stage Stage selected files for the corresponding version control system """ def execute(self): from ranger.ext.vcs import VcsError

    filelist <span style="color:#f92672">=</span> [f<span style="color:#f92672">.</span>path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()]
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>vcs_outdated <span style="color:#f92672">=</span> True

# for f in self.fm.thistab.get_selection(): # f.vcs_outdated = True

    <span style="color:#66d9ef">try</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>vcs<span style="color:#f92672">.</span>add(filelist)
    <span style="color:#66d9ef">except</span> VcsError:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Could not stage files.</span><span style="color:#e6db74">&#34;</span>)

    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>reload_cwd()

class unstage(Command): """ :unstage Unstage selected files for the corresponding version control system """ def execute(self): from ranger.ext.vcs import VcsError

    filelist <span style="color:#f92672">=</span> [f<span style="color:#f92672">.</span>path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()]
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>vcs_outdated <span style="color:#f92672">=</span> True

# for f in self.fm.thistab.get_selection(): # f.vcs_outdated = True

    <span style="color:#66d9ef">try</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>vcs<span style="color:#f92672">.</span>reset(filelist)
    <span style="color:#66d9ef">except</span> VcsError:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Could not unstage files.</span><span style="color:#e6db74">&#34;</span>)

    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>reload_cwd()

class diff(Command): """ :diff Displays a diff of selected files against the last committed version """ def execute(self): from ranger.ext.vcs import VcsError import tempfile

    L <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()
    <span style="color:#66d9ef">if</span> len(L) <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>: <span style="color:#66d9ef">return</span>

    filelist <span style="color:#f92672">=</span> [f<span style="color:#f92672">.</span>path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> L]
    vcs <span style="color:#f92672">=</span> L[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">.</span>vcs

    diff <span style="color:#f92672">=</span> vcs<span style="color:#f92672">.</span>get_raw_diff(filelist<span style="color:#f92672">=</span>filelist)
    <span style="color:#66d9ef">if</span> len(diff<span style="color:#f92672">.</span>strip()) <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>:
        tmp <span style="color:#f92672">=</span> tempfile<span style="color:#f92672">.</span>NamedTemporaryFile()
        tmp<span style="color:#f92672">.</span>write(diff<span style="color:#f92672">.</span>encode(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">utf-8</span><span style="color:#e6db74">&#39;</span>))
        tmp<span style="color:#f92672">.</span>flush()

        pager <span style="color:#f92672">=</span> os<span style="color:#f92672">.</span>environ<span style="color:#f92672">.</span>get(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">PAGER</span><span style="color:#e6db74">&#39;</span>, ranger<span style="color:#f92672">.</span>DEFAULT_PAGER)
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>run([pager, tmp<span style="color:#f92672">.</span>name])
    <span style="color:#66d9ef">else</span>:
        <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">Exception</span>(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">diff is empty</span><span style="color:#e6db74">&#34;</span>)

class log(Command): """ :log Displays the log of the current repo or files """ def execute(self): from ranger.ext.vcs import VcsError import tempfile

    L <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()
    <span style="color:#66d9ef">if</span> len(L) <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>: <span style="color:#66d9ef">return</span>

    filelist <span style="color:#f92672">=</span> [f<span style="color:#f92672">.</span>path <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> L]
    vcs <span style="color:#f92672">=</span> L[<span style="color:#ae81ff">0</span>]<span style="color:#f92672">.</span>vcs

    log <span style="color:#f92672">=</span> vcs<span style="color:#f92672">.</span>get_raw_log(filelist<span style="color:#f92672">=</span>filelist)
    tmp <span style="color:#f92672">=</span> tempfile<span style="color:#f92672">.</span>NamedTemporaryFile()
    tmp<span style="color:#f92672">.</span>write(log<span style="color:#f92672">.</span>encode(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">utf-8</span><span style="color:#e6db74">&#39;</span>))
    tmp<span style="color:#f92672">.</span>flush()

    pager <span style="color:#f92672">=</span> os<span style="color:#f92672">.</span>environ<span style="color:#f92672">.</span>get(<span style="color:#e6db74"></span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">PAGER</span><span style="color:#e6db74">&#39;</span>, ranger<span style="color:#f92672">.</span>DEFAULT_PAGER)
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>run([pager, tmp<span style="color:#f92672">.</span>name])

class flat(Command): """ :flat <level> Flattens the directory view up to the specified level. -1 fully flattened 0 remove flattened view """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    <span style="color:#66d9ef">try</span>:
        level <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
        level <span style="color:#f92672">=</span> int(level)
    <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">ValueError</span>:
        level <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>quantifier
    <span style="color:#66d9ef">if</span> level <span style="color:#f92672">&lt;</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Need an integer number (-1, 0, 1, ...)</span><span style="color:#e6db74">&#34;</span>, bad<span style="color:#f92672">=</span>True)
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>unload()
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>flat <span style="color:#f92672">=</span> level
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>load_content()

# Metadata commands # ——————————–

class prompt_metadata(Command): """ :prompt_metadata <key1> [<key2> [<key3> …]] Prompt the user to input metadata for multiple keys in a row. """

_command_name <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">meta</span><span style="color:#e6db74">&#34;</span>
_console_chain <span style="color:#f92672">=</span> None
<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    prompt_metadata<span style="color:#f92672">.</span>_console_chain <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>args[<span style="color:#ae81ff">1</span>:]
    self<span style="color:#f92672">.</span>_process_command_stack()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_process_command_stack</span>(self):
    <span style="color:#66d9ef">if</span> prompt_metadata<span style="color:#f92672">.</span>_console_chain:
        key <span style="color:#f92672">=</span> prompt_metadata<span style="color:#f92672">.</span>_console_chain<span style="color:#f92672">.</span>pop()
        self<span style="color:#f92672">.</span>_fill_console(key)
    <span style="color:#66d9ef">else</span>:
        <span style="color:#66d9ef">for</span> col <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>browser<span style="color:#f92672">.</span>columns:
            col<span style="color:#f92672">.</span>need_redraw <span style="color:#f92672">=</span> True

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">_fill_console</span>(self, key):
    metadata <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>metadata<span style="color:#f92672">.</span>get_metadata(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path)
    <span style="color:#66d9ef">if</span> key <span style="color:#f92672">in</span> metadata <span style="color:#f92672">and</span> metadata[key]:
        existing_value <span style="color:#f92672">=</span> metadata[key]
    <span style="color:#66d9ef">else</span>:
        existing_value <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">&#34;</span>
    text <span style="color:#f92672">=</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> </span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> </span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> (self<span style="color:#f92672">.</span>_command_name, key, existing_value)
    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>open_console(text, position<span style="color:#f92672">=</span>len(text))

class meta(prompt_metadata): """ :meta <key> [<value>] Change metadata of a file. Deletes the key if value is empty. """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    key <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)
    value <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">1</span>)
    update_dict <span style="color:#f92672">=</span> dict()
    update_dict[key] <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>rest(<span style="color:#ae81ff">2</span>)
    selection <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thistab<span style="color:#f92672">.</span>get_selection()
    <span style="color:#66d9ef">for</span> f <span style="color:#f92672">in</span> selection:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>metadata<span style="color:#f92672">.</span>set_metadata(f<span style="color:#f92672">.</span>path, update_dict)
    self<span style="color:#f92672">.</span>_process_command_stack()

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">tab</span>(self):
    key <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)
    metadata <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>metadata<span style="color:#f92672">.</span>get_metadata(self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>path)
    <span style="color:#66d9ef">if</span> key <span style="color:#f92672">in</span> metadata <span style="color:#f92672">and</span> metadata[key]:
        <span style="color:#66d9ef">return</span> [<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>join([self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">0</span>), self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>), metadata[key]])]
    <span style="color:#66d9ef">else</span>:
        <span style="color:#66d9ef">return</span> [self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">0</span>) <span style="color:#f92672">+</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74"> </span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">+</span> key <span style="color:#66d9ef">for</span> key <span style="color:#f92672">in</span> sorted(metadata)
                <span style="color:#66d9ef">if</span> key<span style="color:#f92672">.</span>startswith(self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>))]

class linemode(default_linemode): """ :linemode <mode> Change what is displayed as a filename. - "mode" may be any of the defined linemodes (see: ranger.core.linemode). "normal" is mapped to "filename". """

<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">execute</span>(self):
    mode <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>arg(<span style="color:#ae81ff">1</span>)

    <span style="color:#66d9ef">if</span> mode <span style="color:#f92672">==</span> <span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">normal</span><span style="color:#e6db74">&#34;</span>:
        mode <span style="color:#f92672">=</span> DEFAULT_LINEMODE

    <span style="color:#66d9ef">if</span> mode <span style="color:#f92672">not</span> <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisfile<span style="color:#f92672">.</span>linemode_dict:
        self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>notify(<span style="color:#e6db74"></span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">Unhandled linemode: `</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#39;</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> mode, bad<span style="color:#f92672">=</span>True)
        <span style="color:#66d9ef">return</span>

    self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>thisdir<span style="color:#f92672">.</span>_set_linemode_of_children(mode)

    <span style="color:#75715e"># Ask the browsercolumns to redraw</span>
    <span style="color:#66d9ef">for</span> col <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>fm<span style="color:#f92672">.</span>ui<span style="color:#f92672">.</span>browser<span style="color:#f92672">.</span>columns:
        col<span style="color:#f92672">.</span>need_redraw <span style="color:#f92672">=</span> True


categories · links · piano · posts · scripts · THEAARBS · home