ranger is a command line file manager that can be extended with python. The commands.py file contains examples of the built in commands:


I can see how to delete files via self.fm.delete() and I have explored the fm.py file and don't see a function that looks to be exposed that would allow me to copy files in a straightforward way (but I'm not a python dev so maybe I don't understand it):


I just want a function that will copy the current selection to a ~/.directory/.

I know I could do this with a key mapping, but I want to do it in python so that I can extend it, but I can't get past this one basic step.


You can have the same function by creating a mapping in your rc.conf file as follows:

map cto shell -f cp %s ~/.special_directory/

Then, you will select the files you need to copy, and press cto.

| improve this answer | |
  • Except for the part where the OP says: “I know I could do this with a key mapping, but I want to do it in python” – Jeff Schaller Sep 22 '18 at 21:23

Welp... this is what I ended up with, but I'm not sure if there is a better way:

class cpto(Command):                                   

    copies the file to a special directory                      
    def execute(self):                                               
        self.fm.execute_console("shell cp %s ~/.special_directory &")

I was able to explore the fm object more in-depth by cloning the ranger repo, cding into it, and running pydoc.ranger.core.actions

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.