You are not logged in.

#1026 2011-07-28 19:38:56

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

Re: Ranger, a textbased filemanager

Cptn_Sandwich wrote:

but still the spawned processes are not properly detached. when ranger dies, they die.

Augh.. this was chaos to implement - and my implementation is hellishly ugly. The problem is that subprocess.Popen doesn't actually support disowned children, AFAIK, so you have to hack around this.

  1. In your configuration directory (~/.config/ranger for most), make a file called 'tempoaryrun' and then give it execute permission (chmod +x tempoaryrun).

  2. In your commands.py add

    class background(Command):
        def execute(self):
            line = parse(self.line)
            if line.chunk(1) and line.chunk(1)[0] == '-':
                flags = line.chunk(1)[1:]
                command = line.rest(2)
            else:
                flags = ''
                command = line.rest(1)
    
            flags+="s"
            if not command and 'p' in flags: command = 'cat %f'
            if command:
                if '%' in command:
                    command = self.fm.substitute_macros(command)
                import ranger
                tempoaryrun=open(ranger.arg.confdir+"/tempoaryrun", "w")
                tempoaryrun.writelines(["zsh -ic "+ranger.ext.shell_escape.shell_quote(command+"< /dev/null & disown")])
                tempoaryrun.close()
                self.fm.execute_command(ranger.arg.confdir+"/tempoaryrun", flags=flags)
    
        def tab(self):
            line = parse(self.line)
            if line.chunk(1) and line.chunk(1)[0] == '-':
                flags = line.chunk(1)[1:]
                command = line.rest(2)
            else:
                flags = ''
                command = line.rest(1)
            start = self.line[0:len(self.line) - len(command)]
    
            try:
                position_of_last_space = command.rindex(" ")
            except ValueError:
                return (start + program + ' ' for program \
                        in get_executables() if program.startswith(command))
            if position_of_last_space == len(command) - 1:
                return self.line + '%s '
            else:
                before_word, start_of_word = self.line.rsplit(' ', 1)
                return (before_word + ' ' + file.shell_escaped_basename \
                        for file in self.fm.env.cwd.files \
                        if file.shell_escaped_basename.startswith(start_of_word))

    ... if you want zsh compatibility (aka. aliases and functions), or

    class background(Command):
        def execute(self):
            line = parse(self.line)
            if line.chunk(1) and line.chunk(1)[0] == '-':
                flags = line.chunk(1)[1:]
                command = line.rest(2)
            else:
                flags = ''
                command = line.rest(1)
    
            flags+="s"
            if not command and 'p' in flags: command = 'cat %f'
            if command:
                if '%' in command:
                    command = self.fm.substitute_macros(command)
                import ranger
                tempoaryrun=open(ranger.arg.confdir+"/tempoaryrun", "w")
                tempoaryrun.writelines([command+"< /dev/null & disown"])
                tempoaryrun.close()
                self.fm.execute_command(ranger.arg.confdir+"/tempoaryrun", flags=flags)
    
        def tab(self):
            line = parse(self.line)
            if line.chunk(1) and line.chunk(1)[0] == '-':
                flags = line.chunk(1)[1:]
                command = line.rest(2)
            else:
                flags = ''
                command = line.rest(1)
            start = self.line[0:len(self.line) - len(command)]
    
            try:
                position_of_last_space = command.rindex(" ")
            except ValueError:
                return (start + program + ' ' for program \
                        in get_executables() if program.startswith(command))
            if position_of_last_space == len(command) - 1:
                return self.line + '%s '
            else:
                before_word, start_of_word = self.line.rsplit(' ', 1)
                return (before_word + ' ' + file.shell_escaped_basename \
                        for file in self.fm.env.cwd.files \
                        if file.shell_escaped_basename.startswith(start_of_word))

    ... if you don't.

NOTE: There's a touch of untested stuff - tell me if it 'not work'. I just fixed one bug now, for example tongue
ANOTHERNOTE (gah - I just don't leave the EDIT button, do I?): I could implement this as a replacement for the 'd' flag /or/ as a new flag for the :shell command - but does anyone want this? I'm fine either way, so if there's no demand I probably wont make it.

Last edited by Veedrac (2011-07-28 19:54:01)

Offline

#1027 2011-07-29 05:45:28

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

Re: Ranger, a textbased filemanager

Cptn_Sandwich wrote:

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

Take a look here (the line with mupdf + add the fix in the following post), I already did this. Unfortunately this doesn't work with mplayer, which we don't know the reason for.

Offline

#1028 2011-07-29 08:49:31

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

Re: Ranger, a textbased filemanager

Army wrote:
Cptn_Sandwich wrote:

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

Take a look here (the line with mupdf + add the fix in the following post), I already did this. Unfortunately this doesn't work with mplayer, which we don't know the reason for.

If you want an implementation that works with mplayer, mine (above) does.
Yours, however is cleaner and works with :open_with, so both have their advantages.

Offline

#1029 2011-08-03 05:45:03

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

Re: Ranger, a textbased filemanager

thanks to you both for your efforts. i will definitely test both ways.
before posting the question i had tried to think up a solution myself but i couldnt find a way around subprocess's Popen.
Maybe with a daemon implementation in python it might work better. but there is none in the standard library i think

Offline

#1030 2011-08-03 21:28:30

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

Re: Ranger, a textbased filemanager

Mplayer doesn't quit when you exit ranger if you exit properly by typing Q or :q!^J. I'm guessing that ranger can't handle it when you close the terminal with some window manager command.

About the zombies: For some reason I don't and never have experienced this problem. But it's indeed true that ranger doesn't always wait for processes, for example if you detach them. As I see it, the problem with waiting is that it blocks and ranger is single-threaded. Hmm..

Veedrac wrote:

How would I make ranger run:

search_file("", offset=0)

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

Are you an emacs user? wink The purpose of "n" is to get to interesting things asap. So by default it will target the newest file.

Veedrac wrote:

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?

Patches, even for minor bugs, are always appreciated. Please use the mailing list or bug tracker.

Veedrac wrote:

The commands configuration file (commands.py) won't overwrite default commands

This is unintended and will be fixed soon.

Army wrote:

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.

In case you want it like that: fm.execute_console saves you the return-press.


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

Offline

#1031 2011-08-04 00:47:50

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

Re: Ranger, a textbased filemanager

hut wrote:

Mplayer doesn't quit when you exit ranger if you exit properly by typing Q or :q!^J. I'm guessing that ranger can't handle it when you close the terminal with some window manager command.

That's good to know - I rarely ever close 'properly' (ranger has its own shortcut and I close everything else with the wm shortcut, so it just seemed natural), so I missed that entirely.
Not with me ;P I tried with the 'd' flag, in case you're wondering. The whole terminal does close, but the post implied that it's be fine as long as I used 'Q' - which I did. It might be related to my (not really mine) zsh hack but that doesn't explain why it doesn't work with :open_with.

Extra info: I use Mplayer2. It shouldn't matter, but you never know.

hut wrote:

Are you an emacs user? wink The purpose of "n" is to get to interesting things asap. So by default it will target the newest file.

Vim, but not a very good one. Thanks for clearing this up - I imagine it'll be more useful now it has an actual order.
I was actually wondering about this because my :travel and :narrow commands used it for their tab implementation, but now that I can see myself using the current implementation for 'n' I'll probably just make a less hacky version tongue [I used it over the command for down because it wraps - but I guess I'll just implement wrapping myself*].

hut wrote:

In case you want it like that: fm.execute_console saves you the return-press.

Cool, how could I have missed that? That makes stuff lots easier.

*Unless, like you seem to have for everything, you've already made that ability somewhere and I just haven't found it yet...

Last edited by Veedrac (2011-08-04 00:49:01)

Offline

#1032 2011-08-04 07:26:38

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

Re: Ranger, a textbased filemanager

Perhaps multiprocessing.active_children() can be used to solve the zombie problem, it will get a list of current child processes and join finished children.
http://docs.python.org/library/multipro … e_children

Offline

#1033 2011-08-04 13:16:40

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

Re: Ranger, a textbased filemanager

cleanrock wrote:

Perhaps multiprocessing.active_children() can be used to solve the zombie problem, it will get a list of current child processes and join finished children.
http://docs.python.org/library/multipro … e_children

Wouldn't that require a move to multiprocessing (ranger uses subprocess currently)? It seems like an awful lot of effort for such little reward. Mind you, I don't tend to see any zombies anyway so this doesn't really affect me.

Offline

#1034 2011-08-05 06:58:04

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

Re: Ranger, a textbased filemanager

hut wrote:

Mplayer doesn't quit when you exit ranger if you exit properly by typing Q or :q!^J. I'm guessing that ranger can't handle it when you close the terminal with some window manager command.

I wrote about this before, maybe I didn't explain it well enough:
There are two ways to start ranger.

First way: Open a terminal, write "ranger" and hit Enter. If you start ranger that way, mplayer won't quit if ranger is quit with Q.
Second way: Use e.g. dmenu and execute "/usr/bin/urxvtc -e /usr/bin/ranger" (I configured a keybinding in my wm to execute that command). This way, mplayer will quit if you quit ranger.

This only happens with mplayer. I think I'll ask on the mplayer mailing list, I am already suscribed to that. Maybe they know why that happens.

Offline

#1035 2011-08-07 01:02:05

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

Re: Ranger, a textbased filemanager

Army wrote:

This only happens with mplayer. I think I'll ask on the mplayer mailing list, I am already suscribed to that. Maybe they know why that happens.

This is odd.. but it isn't only ranger. Zathura does it. I haven't tested anything else.

OFFTOPIC:

Army wrote:

Second way: Use e.g. dmenu and execute "/usr/bin/urxvtc -e /usr/bin/ranger" (I configured a keybinding in my wm to execute that command). This way, mplayer will quit if you quit ranger.

I've seen it before, but never understood why: is there a reason you use "/usr/bin/ranger" over just "ranger"?

Offline

#1036 2011-08-10 21:34:45

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Ranger, a textbased filemanager

I'm not really sure, but did ranger switch from python's file utils to coreutils at some time? I'm trying ranger out on OSX and while the program itself runs fine the file operations error out, possibly because of inconsistencies between the bsd and gnu cp/mv implementations.

@hut: do you still intend to keep *nix compatibility, or should i hack around this locally?


ᶘ ᵒᴥᵒᶅ

Offline

#1037 2011-08-11 18:36:32

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

Re: Ranger, a textbased filemanager

Can you hack around it and send me a diff? I dont have a bsd machine here to test it on.

And yes, ranger uses GNU cp/mv atm.


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

Offline

#1038 2011-08-13 11:19:34

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Ranger, a textbased filemanager

hut wrote:

Can you hack around it and send me a diff? I dont have a bsd machine here to test it on.

And yes, ranger uses GNU cp/mv atm.

It looks like only the backup=numbered flag is giving problems, bsd cp/mv doesn't support making automatic backups. So for compatibility, ranger itself would have to check if a file already exists, and copy it to a different filename if it does. My python skills are close to zero though, so if you would consider implementing this i will be glad to hand it over to you. smile


ᶘ ᵒᴥᵒᶅ

Offline

#1039 2011-08-13 11:38:42

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

Re: Ranger, a textbased filemanager

litemotiv wrote:
hut wrote:

Can you hack around it and send me a diff? I dont have a bsd machine here to test it on.

And yes, ranger uses GNU cp/mv atm.

It looks like only the backup=numbered flag is giving problems, bsd cp/mv doesn't support making automatic backups. So for compatibility, ranger itself would have to check if a file already exists, and copy it to a different filename if it does. My python skills are close to zero though, so if you would consider implementing this i will be glad to hand it over to you. smile

Oh, I'll be glad to. I think I even have some old code that takes care of that.

EDIT: More complicated than I thought. Ranger copies everything in bulk, like "cp file1 file2 file3 destination/" and without automatic backups, i'd have to break it up into multiple cp commands, "cp file1 destination/file1_" for each file...

Last edited by hut (2011-08-13 12:47:00)


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

Offline

#1040 2011-08-14 22:45:16

fartman
Member
Registered: 2011-08-14
Posts: 3

Re: Ranger, a textbased filemanager

HI. New to this great soft.

I wanted to run vim in detached mode. I found this way:

[shift+! to enter shell mode] gnome-terminal -x vim %f

This just lunches gnome terminal and by-passes (-x) the command vim %f, where as u know %f is the file selected or under the cursor

Tell me if there is an easier way!  This may serve for those who wanted to detach other text based applications. I didn't read all the posts but I think nobody found a solution for that

Offline

#1041 2011-08-14 22:58:51

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

Re: Ranger, a textbased filemanager

hi fartman. Thats the easiest way to do it indeed. But you can make a shortcut for it. For example, by copying the config file for key bindings with the command "ranger --copy-config=keys" and then adding your command to it. Take the "yn" key as a reference.


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

Offline

#1042 2011-08-15 01:28:02

fartman
Member
Registered: 2011-08-14
Posts: 3

Re: Ranger, a textbased filemanager

Hi hut. Thanks for such a fast response!

In the meantime i found my way by modifying the actions.py in /core, mapping "%j" to "gnome-terminal -x vim". So ":shell %j %f" did the job

Nevertheless, you way is faster and much cleaner! Didn't know about that 'keys.py'. Thanks again!

Offline

#1043 2011-08-15 14:34:43

fartman
Member
Registered: 2011-08-14
Posts: 3

Re: Ranger, a textbased filemanager

I've been investigating more on ranger. Keeping on the idea of detaching things from ranger, running :shell gnome-terminal -x python %f    did run the file, but the terminal closed. So my method is copying the file name inside ranger and open a terminal and run that file in a certain program, all done with fast scripts:

1)Place yourself over a folder in ranger and run :shell echo $PWD/%f|xclip     (requires program xclip)
That commands copies the directory together with the file name (check it by running xclip -o). You may create a key binding for that.

2)Put this funtion in bashrc
whatever()
{
   n1=$(xclip -o)
   n2=$(echo $n1|sed 's/^/'"$1"' /')
   $($n2)
   return
}


Then, open a terminal and, once the file name is in the clipboard (check it by running xclip -o), run:
user@computer:~$whatever python
And that will run the file name saved in the clipboard in python. Notice u can copy the name of e.g. an image and run "whatever gimp", and it will launch that image in gimp.

Offline

#1044 2011-08-15 19:44:55

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

Re: Ranger, a textbased filemanager

fartman wrote:

1)Place yourself over a folder in ranger and run :shell echo $PWD/%f|xclip     (requires program xclip)
That commands copies the directory together with the file name (check it by running xclip -o). You may create a key binding for that.

Typing yp does exactly this.

Offline

#1045 2011-08-20 16:35:04

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

Re: Ranger, a textbased filemanager

Hi all,

I've been using Ranger in urxvt for a few months now and I love it. The only thing I've noticed is that it tends to use more system resources than say, Midnight Commander, when 'scrolling' through a directory or holding down Space to select multiple files. It has some noticeable lag in that regard. Is there anything I can do on my end to make it run a little smoother? Could it be because I have xft fonts enabled?

My Xdefaults can be found here: http://pastebin.com/WcTRGjLt

Many thanks!

Offline

#1046 2011-08-21 11:42:42

Revolt
Member
From: Portugal
Registered: 2009-06-11
Posts: 71
Website

Re: Ranger, a textbased filemanager

Did you try disabling the file previews (zp) sensory? Without them my ranger scrolls super fast wink

Offline

#1047 2011-08-21 15:08:21

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

Re: Ranger, a textbased filemanager

Yes, generating previews is quite a performance sink. You can disable them by default in the config:

~/.config/ranger/options.py:
preview_files = False

And turn on/off the previews on demand, with zp, as Revolt said.

@litemotiv:
sorry, i can't work on it atm. but I guess you already made a workaround by now. If not: simply remove the --backup=numbered flag smile


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

Offline

#1048 2011-08-21 15:27:49

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Ranger, a textbased filemanager

hut wrote:

@litemotiv:
sorry, i can't work on it atm. but I guess you already made a workaround by now. If not: simply remove the --backup=numbered flag smile

Yes that's what i did, no problem. smile


ᶘ ᵒᴥᵒᶅ

Offline

#1049 2011-08-22 23:14:13

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

Re: Ranger, a textbased filemanager

Some news:

1. You can now use any ascii character for tagging, rather than just "*", by typing "x with x being the tag name. This feature does not break tags of older ranger versions.
2. Added shortcuts for chmod: Typing +ux will execute chmod u+x %s and this works with any combinations. -ow does chmod o-w %s and =666 does chmod 666 %s. See "man chmod"
3. Added sorting by ctime: oc

Last edited by hut (2011-08-23 08:31:36)


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

Offline

#1050 2011-08-23 20:35:34

saline
Member
Registered: 2010-02-20
Posts: 86

Re: Ranger, a textbased filemanager

hut wrote:

Some news:

1. You can now use any ascii character for tagging, rather than just "*", by typing "x with x being the tag name. This feature does not break tags of older ranger versions.
2. Added shortcuts for chmod: Typing +ux will execute chmod u+x %s and this works with any combinations. -ow does chmod o-w %s and =666 does chmod 666 %s. See "man chmod"
3. Added sorting by ctime: oc

This is excellent.  Great idea!

Offline

Board footer

Powered by FluxBB