Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Ranger自定义命令将文件移动到预先指定的目录?_Bash_Shell - Fatal编程技术网

Bash Ranger自定义命令将文件移动到预先指定的目录?

Bash Ranger自定义命令将文件移动到预先指定的目录?,bash,shell,Bash,Shell,使用ranger 如何创建一个:命令,将当前选定的文件移动到预先指定的目录?比如说,通过选择一个文件并键入:移动到它运行的路径 mv文件/路径/位置/文件 如何与(1)中的操作相同,而是绑定一个键:command?例如,突出显示一个文件并键入它在所选文件上运行的mf:move_to_path 编辑 问题是关于这个游侠的:我不是游侠用户,但我在游侠维基中看到了一个似乎很有用的条目: TL;DR:编辑文件~/.config/ranger/commands.py from ranger.api.c

使用ranger

  • 如何创建一个
    :命令
    ,将当前选定的文件移动到预先指定的目录?比如说,通过选择一个
    文件
    并键入
    :移动到它运行的路径

    mv文件/路径/位置/文件

  • 如何与(1)中的操作相同,而是绑定一个键
    :command
    ?例如,突出显示一个文件并键入它在所选文件上运行的
    mf
    :move_to_path

  • 编辑
    问题是关于这个游侠的:

    我不是游侠用户,但我在游侠维基中看到了一个似乎很有用的条目:

    TL;DR:编辑文件
    ~/.config/ranger/commands.py

    from ranger.api.commands import Command
    class move_to_path(Command):
        """
        :move_to_path
        Move file to a directory
        """
        def execute(self):
            import shutil # for shutil.copy, os.rename works fine too
            shutil.move(self.fm.thisfile.path, "/your/directory/" + self.fm.thisfile.basename)
    
    现在,您可以使用
    :move_to_path
    启动命令。您可以编写python代码来知道从何处获取目录名:fixed,在您选择的配置文件中,等等

    现在,要添加键绑定,让我们看一下:或: 如果我没有错,您可以编辑
    ~/.config/ranger/config/rc.conf
    并在这里添加一个键绑定。 例如,可以添加一行:

    map mf move_to_path
    
    我认为这应该能奏效。 谢谢你让我发现了流浪者,我明天会试试:)

    编辑: 要移动多个选定文件,可以执行以下操作:

        def execute(self):
            import shutil # for shutil.copy, os.rename works fine too
            from os import basename
            for file in self.fm.thistab.get_selection():
                shutil.move(file, "/your/directory/" + basename(file))
    

    这很好用,除了它不是
    ~/.config/ranger/config/rc.conf
    之外,它实际上是
    ~/.config/ranger/rc.conf
    需要使用
    map mf move\u to\u path
    进行编辑。另外:你知道有没有一种简单的方法可以让这个命令影响选定的文件,而不是当前查看的文件?我必须尝试给出一个可接受的答案,但是我认为github上的wiki包含了很多信息,也可以通过查看python源文件获得一些提示。我将编辑答案。