How to script ranger to copy a file to another directory via python

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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



https://github.com/ranger/ranger/blob/master/ranger/config/commands.py



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):



https://github.com/ranger/ranger/blob/master/ranger/core/fm.py



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.










share|improve this question

























    up vote
    0
    down vote

    favorite












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



    https://github.com/ranger/ranger/blob/master/ranger/config/commands.py



    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):



    https://github.com/ranger/ranger/blob/master/ranger/core/fm.py



    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.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











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



      https://github.com/ranger/ranger/blob/master/ranger/config/commands.py



      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):



      https://github.com/ranger/ranger/blob/master/ranger/core/fm.py



      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.










      share|improve this question













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



      https://github.com/ranger/ranger/blob/master/ranger/config/commands.py



      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):



      https://github.com/ranger/ranger/blob/master/ranger/core/fm.py



      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.







      python ranger






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 20 '17 at 18:32









      hermancain

      699612




      699612




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










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



          class cpto(Command): 
          """:cpto

          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






          share|improve this answer



























            up vote
            0
            down vote













            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.






            share|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 at 21:23










            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f338941%2fhow-to-script-ranger-to-copy-a-file-to-another-directory-via-python%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










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



            class cpto(Command): 
            """:cpto

            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






            share|improve this answer
























              up vote
              0
              down vote



              accepted










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



              class cpto(Command): 
              """:cpto

              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






              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






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



                class cpto(Command): 
                """:cpto

                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






                share|improve this answer












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



                class cpto(Command): 
                """:cpto

                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 20 '17 at 20:15









                hermancain

                699612




                699612






















                    up vote
                    0
                    down vote













                    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.






                    share|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 at 21:23














                    up vote
                    0
                    down vote













                    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.






                    share|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 at 21:23












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    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.






                    share|improve this answer












                    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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 22 at 20:54









                    user314583

                    1




                    1











                    • 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 at 21:23
















                    • 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 at 21:23















                    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 at 21:23




                    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 at 21:23

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f338941%2fhow-to-script-ranger-to-copy-a-file-to-another-directory-via-python%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay