You are not logged in.

#1001 2011-07-12 19:34:03

chimerical_brio
Member
Registered: 2008-07-20
Posts: 38

Re: Ranger, a textbased filemanager

So I've put the following at the bottom of ~/.config/ranger/keys.py but it doesn't work as intended (to move items to the directory /home/henry/.trash):

@map('DD')
def movetotrash(arg):
    trash_dir="/home/henry/.trash"
    selection = arg.fm.env.get_selection()
    arg.fm.run(['mv', '-t', trash_dir] + [str(f) for f in selection])

Presumably I would type DD and it would move it to the trash location, but that doesn't work. Can anyone help me?

Offline

#1002 2011-07-14 00:27:47

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

I don't know. It works for me. Does the directory exist?


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1003 2011-07-16 14:57:57

sensory
Member
From: UK
Registered: 2010-05-01
Posts: 40

Re: Ranger, a textbased filemanager

I just switched to Ranger from Midnight Commander and I'm loving it so far.

Is there a way in Ranger to see the size of a folder, including sub-folders? Because right now I can only see how many files are in said folder and Ranger doesn't show the size for sub-folders. Just a key-combination would be great, like MC's CTRL+SPACE.

Offline

#1004 2011-07-16 18:25:27

igndenok
Member
From: Sidoarjo, Indonesia
Registered: 2010-06-07
Posts: 160

Re: Ranger, a textbased filemanager

Using du (type d then u) ?!


Ask, and it shall be given you.
Seek, and ye shall find.
Knock, and it shall be opened unto you.

Offline

#1005 2011-07-16 18:57:30

sensory
Member
From: UK
Registered: 2010-05-01
Posts: 40

Re: Ranger, a textbased filemanager

igndenok wrote:

Using du (type d then u) ?!

That works, thanks.

Offline

#1006 2011-07-19 17:29:12

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

Thanks, hut, for the joys I've had with ranger.

First of all, I have found some very minor bugs/errors, and I was wondering if and where I should report them.
I would put them on http://savannah.nongnu.org/bugs/, but it doesn't seem as active as here.
The most annoying of these is that the default search (AKA when I press 'n' before I've done a search) is really messed up. How would I make ranger run:

search_file("", offset=0)

... upon start-up?

Secondly, I haven't been able to overwrite inbuilt commands (notably :find and :search_inc). What should I do!?

Thank you in advance.

And, lastly, I have said code:
... which I want to make execute as soon as there is only one visible file. Not understanding how any of this works, I added:
... to the quick() method - but it always takes one non-cancelling key-press (any key but ESC) after it is filtered for it to work. I imagined you lot might know what was up.
I do know that there was a :live_filter that does basically what I want, but I don't want to add ~20 lines of code where I previously had 1, especially when I don't understand why it works (which makes it really hard to configure/bugfix it), AND getting this code working would be useful in the future for me.

EDIT: I've solved it!
The cleanest and most complete so far posted:

class narrow(Command):
    """
    :narrow <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection and removes the filter.
    """

    def execute(self):
        self.fm.set_filter("")
        self.fm.reload_cwd()
        self.fm.move(right=1)
        self.fm.block_input(0.5)

    def cancel(self):
        self.fm.set_filter("")
        self.fm.reload_cwd()

    def quick(self):
        self.fm.set_filter(parse(self.line).rest(1))
        self.fm.reload_cwd()

    def tab(self):
        self.fm.search()

class travel(Command):
    """
    :travel <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection, removes the filter and starts another :travel command.
    """

    special = False

    def execute(self):
        self.fm.set_filter("")
        self.fm.reload_cwd()

        if self.special:
            self.fm.cd(self.special)
            if self.special != "..":
                self.fm.block_input(0.5)
            self.special = False
        else:
            self.fm.move(right=1)

        self.fm.open_console('travel ')

    def cancel(self):
        self.fm.set_filter("")
        self.fm.reload_cwd()

    def quick(self):
        arg = parse(self.line).rest(1)
        self.fm.set_filter(arg)
        self.fm.reload_cwd()

        if arg == ".":
            return False
        if arg == "..":
            self.special = ".."
            return True
    
        filtered_files = [d for d in self.fm.env.cwd.files if d.basename.count(arg)]
        if len(filtered_files)==1:
            self.special = filtered_files[0].basename
            return True

    def tab(self):
        self.fm.search()

Last edited by Veedrac (2011-07-21 02:15:04)

Offline

#1007 2011-07-20 13:01:48

NoxSec
Member
Registered: 2011-07-13
Posts: 38

Re: Ranger, a textbased filemanager

Very nice, I generally just use the terminal and thunar when I am feeling lazy. However, I think this has just replaced thunar for me.

Offline

#1008 2011-07-20 17:31:18

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Hello! I`ve looked  throuh this topic and the help inside ranger, but still have a question: is there any way to select only plain files (without directories) with "v" key? Sorry if the quiestion is stupid.

Wow! Using zsh as ranger`s shell I broke the ouput of my terminal when tried to copy file`s path or name, etc. with 'yp', 'yn', so on.

Last edited by loop (2011-07-20 22:15:17)

Offline

#1009 2011-07-21 02:06:47

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

loop wrote:

Hello! I`ve looked  throuh this topic and the help inside ranger, but still have a question: is there any way to select only plain files (without directories) with "v" key? Sorry if the quiestion is stupid.

I assume you just want to select all files on your system - 'plain files' is a bit ambiguous.
There are two ways you can go about this. If you are lucky enough to have no directories with "." in them, and all the files do, just use ":mark ."

However, you alternative is to slap:

class markFiles(Command):
    """
    :markFiles <regexp>

    Mark all files, but not directories, matching a regular expression.
    """
    do_mark = True
    allow_abbrev = False

    def execute(self):
        import re
        cwd = self.fm.env.cwd
        line = parse(self.line)
        input = line.rest(1)
        searchflags = re.UNICODE
        if input.lower() == input: # "smartcase"
            searchflags |= re.IGNORECASE 
        pattern = re.compile(input, searchflags)
        for fileobj in cwd.files:
            if pattern.search(fileobj.basename) and fileobj.is_file:
                cwd.mark_item(fileobj, val=self.do_mark)
        self.fm.ui.status.need_redraw = True
        self.fm.ui.need_redraw = True
class unmarkFiles(markFiles):
    """
    :markFiles <regexp>

    Mark all files, but not directories, matching a regular expression.
    """
    do_mark = False
    allow_abbrev = False

... on to your commands.py
Enjoy! If you want one for selecting directories, just change "if pattern.search(fileobj.basename) and fileobj.is_file:" to "if pattern.search(fileobj.basename) and fileobj.is_directory:".

Wow! Using zsh as ranger`s shell I broke the ouput of my terminal when tried to copy file`s path or name, etc. with 'yp', 'yn', so on.

Do explain...

If anyone wants, there's something else I've made:
Add this to your config, run :toggleFiles, and ranger becomes a directory-switcher (no files are displayed).
Additionally you can toggle directories, but it makes everything a bit off...

# Toggles for the display of files or folders.

import ranger.fsobject
ranger.fsobject.hideDirs = False
ranger.fsobject.hideFiles = False

def custom_accept_file(fname, dirname, hidden_filter, name_filter):
    import os.path as path 
    fs = ranger.fsobject
    if hidden_filter:
        try:
            if hidden_filter.search(fname):
                return False
        except:
            if hidden_filter in fname:
                return False
    if (name_filter and name_filter not in fname) or (fs.hideDirs and path.isdir(dirname+"/"+fname)) or (fs.hideFiles and not path.isdir(dirname+"/"+fname)):
        return False
    return True
ranger.fsobject.directory.accept_file = custom_accept_file

class toggleDirs(Command):
    """
    :toggleDirs

    Unlike toggleFiles, I'm not sure why anyone would want to use this, now that :markDirs exists...
    Does not take arguments.
    """
    def execute(self):
        ranger.fsobject.hideDirs = not ranger.fsobject.hideDirs

        # We could just run .load_content() for every directory, but it saves a /lot/ of time to just do it on the visible ones and unload the rest.
        for directory in self.fm.env.directories:
            self.fm.env.directories[directory].unload()
        for directory in [d for d in self.fm.env.directories if d.count(self.fm.env.path) or self.fm.env.path.count(d)]:
            if not directory: directory = '/'
            self.fm.env.directories[directory].load_content()

class toggleFiles(Command):
    """
    :toggleFiles

    Turns off file display; useful if you want to switch ranger into a sort of 'navigation mode'.
    Does not take arguments.
    """
    def execute(self):
        ranger.fsobject.hideFiles = not ranger.fsobject.hideFiles

        # We could just run .load_content() for every directory, but it saves a /lot/ of time to just do it on the visible ones and unload the rest.
        for directory in self.fm.env.directories:
            self.fm.env.directories[directory].unload()
        for directory in [d for d in self.fm.env.directories if d.count(self.fm.env.path) or self.fm.env.path.count(d)]:
            if not directory: directory = '/'
            self.fm.env.directories[directory].load_content()

It has also come to my attention that spoiler tags would be useful to paste some code in. smile

Offline

#1010 2011-07-21 07:47:39

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Veedrac, thank you, your code works for me!

Does anybody got ranger work well with zsh as shell? I`ve edited commands.py (as @hut adviced in post #977), but ranger falls to background after most shell commands now.

Offline

#1011 2011-07-21 11:56:09

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

loop wrote:

Veedrac, thank you, your code works for me!

Does anybody got ranger work well with zsh as shell? I`ve edited commands.py (as @hut adviced in post #977), but ranger falls to background after most shell commands now.

Ah - I get the same thing with the third implementation.
I'll try the others now... EDIT: and they fail too...

I can't see an obvious cause but I'll try and find a cure.

Last edited by Veedrac (2011-07-21 12:22:13)

Offline

#1012 2011-07-21 12:55:13

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Veedrac wrote:

I can't see an obvious cause but I'll try and find a cure.

That would be great! Thank you in advance.

Offline

#1013 2011-07-21 13:49:45

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

In the part that goes "-ic", remove the "i".

Oh - tell me if you aliases work as well as if the crashing stops.

EDIT: EDIT: ignore this - I might have a better idea...
loop said that he got aliases to work with the code despite ranger going into background. I don't seem to manage this - but I can get aliases to not work and keep ranger in the foreground...
In other words, I have no idea. You can try the 'solution' at the top, but I doubt it will help.

What do you want zsh for? If it is to let you set aliases, I could probably whip up an :alias command to simulate it...

Last edited by Veedrac (2011-07-21 14:18:29)

Offline

#1014 2011-07-21 14:19:47

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Veedrac wrote:

In the part that goes "-ic", remove the "i".

Oh - tell me if you aliases work as well as if the crashing stops.

EDIT: EDIT: ignore this - I might have a better idea...
loop said that he got aliases to work with the code despite ranger going into background. I don't seem to manage this - but I can get aliases to not work and keep ranger in the foreground...
In other words, I have no idea. You can try the 'solution' at the top, but I doubt it will help.

You are right, removing "i" prevent ranger from background falls, but my custom zsh stuff (such as aliases, functions, hashes) can`t run either. I hope, this sad thing will get developers attention some day.

Offline

#1015 2011-07-21 15:27:45

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

loop wrote:

You are right, removing "i" prevent ranger from background falls, but my custom zsh stuff (such as aliases, functions, hashes) can`t run either. I hope, this sad thing will get developers attention some day.

You seem more knowledgeable than I, so I'll point out that I think the problem lies around Popen in core/runner.py (but piping is beyond me so I sort of got lost from there).

Ranger is powerful enough that I imagine each function/alias/etc. could be transferred over, but if you have more than a few I agree that it's less than ideal.

Last edited by Veedrac (2011-07-21 15:29:09)

Offline

#1016 2011-07-24 13:09:24

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

Well, I've solved it.
It probably has its drawbacks, but I haven't found any yet:

self.fm.execute_command(["zsh", "-ic", "--no-monitor", command], flags=flags)

And thus your Zsh works!

Last edited by Veedrac (2011-07-24 13:42:49)

Offline

#1017 2011-07-24 16:45:04

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Hello, Veedrac.
Seems it works! I appreciate for your help very much!

Offline

#1018 2011-07-25 09:13:25

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Hello everybody!
How can I run executable scripts with "Enter" key?
The doc says it can be run with command ":open_with self", but it`s take five keys to be pressed instead of one.

Offline

#1019 2011-07-25 10:05:14

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Ranger, a textbased filemanager

You can do this e.g. with something like this

% cat ~/.config/ranger/keys.py
from ranger.api.keys import *
map = keymanager.get_context('browser')
map('X', fm.open_console('open_with self'))

This way, all you have to do is press X+Return.

Offline

#1020 2011-07-25 10:39:09

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Thank you, Army.

Offline

#1021 2011-07-26 01:01:11

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

Something more akin to what you originally asked for:

@map('X')
def self_run(arg):
    arg.fm.execute_file(files=[f for f in arg.fm.env.cwd.get_selection()], app="self")

You don't need a return for this one.

Also, since I seem to have drowned my own post, I'll re-hash it in a tad more detail:

  1. How would I make ranger run:

    search_file("", offset=0)

    ...on start up, or fix the odd default behavior of the 'n' key?

  2. Is it worth reporting my minor bugs - mostly formatting or similar - and where should I do so, if so? I could make some patches, but will they be used?

  3. The commands configuration file (commands.py) won't overwrite default commands. How would I make it do so (so I don't have to re-install ranger [sudo make install] each time I change any of them, and to centralize my configurations)?
    EDIT: I've had another go at this, and it seems all the stuff I've been doing with ranger gave me the skills to solve this myself. For anyone who wants the code, in core/ranger.py change:

        try:
            import commands
            comcont.load_commands_from_module(commands)
        except ImportError:
            pass
        from ranger.defaults import commands
        comcont.load_commands_from_module(commands)

...for:

        from ranger.defaults import commands
        comcont.load_commands_from_module(commands)
        try:
            import commands
            comcont.load_commands_from_module(commands)
        except ImportError:
            pass

Last edited by Veedrac (2011-07-26 18:30:59)

Offline

#1022 2011-07-28 05:53:22

Cptn_Sandwich
Member
Registered: 2010-11-07
Posts: 13

Re: Ranger, a textbased filemanager

I have very annoying that viewers spawned by ranger exit when ranger exits.
for example i opened a pdf in evince from ranger. i would like evince to stay when ranger exits. just like in a gui file manager

Offline

#1023 2011-07-28 15:27:35

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Starting programs in the background

In many cases, launching a file will make Ranger unusable until the program you used to launch the file is closed. The following example shows how to change this for html files. In ~/.ranger/apps.py, change

if f.extension in ('html', 'htm', 'xhtml', 'swf'):
    return self.either(c, 'firefox', 'opera', 'elinks')

to

if f.extension in ('html', 'htm', 'xhtml', 'swf'):
    c.flags += 'd'
    return self.either(c, 'firefox', 'opera')

From https://wiki.archlinux.org/index.php/Ranger

Offline

#1024 2011-07-28 15:47:54

Cptn_Sandwich
Member
Registered: 2010-11-07
Posts: 13

Re: Ranger, a textbased filemanager

thanks loop, that is one step in the right direction. now ranger doesnt block anymore.
but still the spawned processes are not properly detached. when ranger dies, they die.
unlike with nautilus, thunar, ...
EDIT: thats already standard behaviour. customizing .ranger/apps.py doesnt make a difference there

Last edited by Cptn_Sandwich (2011-07-28 15:50:53)

Offline

#1025 2011-07-28 16:26:01

cleanrock
Member
Registered: 2008-11-17
Posts: 109

Re: Ranger, a textbased filemanager

.. and please remove the zombies left when child exits.

Offline

Board footer

Powered by FluxBB