You are not logged in.

#326 2010-05-19 20:34:25

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

Ranger is some great file manager, really like the design of this. I have a couple of questions:

1. Is there a 'screen' mode so you can open a file in a new screen window instead of the same window as Ranger?
2. If I choose to open an image file in a directory, Ranger opens all images in that directory with the same file ending in feh. Should this be so?

Offline

#327 2010-05-19 20:43:07

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

Re: Ranger, a textbased filemanager

Thanks jostber

1. No, there is no such thing built in.
I'm not sure what you mean, but if there is a way to do it in python (e.g. with a shell command), then you can simply modify your apps.py.

2. This is a feature. I thought about removing it several times now because it's not the expected behaviour,... but I was too lazy, until now.


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

Offline

#328 2010-05-19 20:49:59

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

In 1. I mean like the function in vifm where you can run :screen and then all text files opens in a new screen window instead of the same window as Ranger. That makes it possible to use Ranger even if you have opened one file.

Offline

#329 2010-05-19 21:03:28

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

Re: Ranger, a textbased filemanager

Try writing something like this in your ~/.ranger/apps.py:

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        if c.mode is 2:
            c.flags += 'd'
            return tup("xterm", "-e", "vim", *c)
        else:
            return tup("vim", *c)

Now open text files in mode 2, by typing 2<enter> or 2l

This is without screen, I'm still not sure why screen is needed here


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

Offline

#330 2010-05-19 21:07:30

yvonney
Member
Registered: 2008-06-11
Posts: 671

Re: Ranger, a textbased filemanager

UPDATE COMMENT: ooo! just saw the above code, thanks hut! maybe you posted while I was typing what's below.

- - - - - - - written earlier than the above - - - - - - -

someday objective: it's likely an aside though getting 
tmux and ranger so that opening a text file occurs in the same 
tmux window as RANGER's running in, with the text file opening 
in a 'pane' beside ranger.

If the 'screen' request was tmux-ised that would be cool. If I understand correctly that is.
I use RANGER all day long. When I open, say, a text file, it opens up the text file in vim, (ranger disappears) then, after closing the text file I start RANGER up again. Or, RANGER's still as it was prior to opening the text file.

[I'm wrong I now think] >>> Actually, it's when I do a shift-s to go into a folder to do a 'make' or something that requires I restart RANGER afterwards from prompt.    of course!

I considered that it was my lack of skill or just the way it is.

Currently I start RANGER and a ton of others all in TMUX.
Not quite sure what I'm thinking though perhaps I'm meaning that RANGER could open text files in a 'pane' right beside the window that RANGER is running in, within TMUX.

All the above aside, there's probably a way to add something to the RANGER .py file mentioned to have all possible files open up in a tmux side 'pane' in the same tmux 'window' that RANGER is running in.

Last edited by yvonney (2010-05-19 21:56:22)

Offline

#331 2010-05-19 21:31:03

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

hut wrote:

Try writing something like this in your ~/.ranger/apps.py:

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        if c.mode is 2:
            c.flags += 'd'
            return tup("xterm", "-e", "vim", *c)
        else:
            return tup("vim", *c)

Now open text files in mode 2, by typing 2<enter> or 2l

This is without screen, I'm still not sure why screen is needed here

Thanks, I entered this into apps.py but the behavior for the text file is the same, it occupies the whole window when I open it. I use screen for all my terminal windows, and it would be nice if Ranger could open a text file in a new screen window so I would have full access to the file manager even with a file open.

Offline

#332 2010-05-19 21:34:34

yvonney
Member
Registered: 2008-06-11
Posts: 671

Re: Ranger, a textbased filemanager

UPDATE: sorry, seem to be fixed. had to kill process properly. tmux saved session of course.
So, just need to see if  urxvt or urxvtc is best for line 7 as below.

- - - - - - - below written first - - - - - - -


tried to fix what I think 'may' be a python whitespace issue and of course general not-knowingness.

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        if c.mode is 2:
            c.flags += 'd'
            return tup("urxvtc", "-e", "vim", *c)
        else:
            return tup("vim", *c)

Fatal: unexpected indent (apps.py, line 7)
A traceback has been saved to ~/.ranger/traceback
Please include it in a bugreport.

Also, I use urxvtc so would I put  urxvt or urxvtc ?

Last edited by yvonney (2010-05-19 21:43:21)

Offline

#333 2010-05-19 21:57:07

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

Re: Ranger, a textbased filemanager

jostber wrote:

Thanks, I entered this into apps.py but the behavior for the text file is the same, it occupies the whole window when I open it. I use screen for all my terminal windows, and it would be nice if Ranger could open a text file in a new screen window so I would have full access to the file manager even with a file open.

I think I get it now. Ranger runs inside a screen session and you want to open the file in a new window in the same screen session.

Here's a way that works [for me] with tmux, its not perfect but a start:
(It seems that the whole vim-command has to be squashed into one string, so filenames with spaces need special treatment with shell_escape)

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        if c.mode is 2:
            from ranger.ext.shell_escape import shell_escape
            return tup("tmux", "split-window", "-v", "vim " + "".join(shell_escape(name) for name in c))
        else:
            return tup("vim", *c)

Don't know about screen, I don't use it. Try something like this?

return tup("screen", "-S", <your-session>, "-X", <command-to-create-new-window>, "vim " + "".join(shell_escape(name) for name in c))

(put this line instead of the tmux line above)


Fatal: unexpected indent (apps.py, line 7)
A traceback has been saved to ~/.ranger/traceback
Please include it in a bugreport.

You probably mixed up spaces with tabs. To reformat the code in vim, type ggVG=

Last edited by hut (2010-05-19 22:09:00)


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

Offline

#334 2010-05-19 23:10:16

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

Thanks, I tried the screen command, but it is the same result. There is no difference if I open the file in mode 1 or 2, the file is always opened in the same terminal window.

Offline

#335 2010-05-19 23:22:00

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

Re: Ranger, a textbased filemanager

jostber wrote:

Thanks, I tried the screen command, but it is the same result. There is no difference if I open the file in mode 1 or 2, the file is always opened in the same terminal window.

Hmm first let's ensure that the code is actually used by the program.
after the line "def app_vim..." write this:

raise Exception("Yes!")

If you open a file now, it should say "Yes!" instead of starting vim?

Another thing:
I hope it's clear that the screen command I posted is not complete. Fill in the parts in <> brackets, I don't know exactly how it works (or if it even works like that).


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

Offline

#336 2010-05-19 23:23:22

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

Opening a text file in a new screen window works if I run

!screen -t %s vim %f

on the file directly, but the code for screen in apps.py is not working.


.

Last edited by jostber (2010-05-19 23:24:39)

Offline

#337 2010-05-19 23:29:44

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

Re: Ranger, a textbased filemanager

Oh, excellent, then just use this:

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        return tup("screen", "-t", c.file.basename, "vim", *c)

Last edited by hut (2010-05-19 23:30:06)


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

Offline

#338 2010-05-19 23:30:15

yvonney
Member
Registered: 2008-06-11
Posts: 671

Re: Ranger, a textbased filemanager

[indenting non-issue and hut's tmux tips]

I did an UPDATE of one of my posts above, which at the speed you help us here by posting I knew it could be possibly too slow of me to restate that I'd realized my indenting puzzle was me not killing then starting tmux again I think. no matter of course.

So....! anyways! FANTASTIC that you use TMUX with RANGER !!! thanks, will be working with that later!

Last edited by yvonney (2010-05-19 23:32:24)

Offline

#339 2010-05-19 23:47:24

yvonney
Member
Registered: 2008-06-11
Posts: 671

Re: Ranger, a textbased filemanager

Here's a way that works [for me] with tmux, its not perfect but a start:
(It seems that the whole vim-command has to be squashed into one string, 
so filenames with spaces need special treatment with shell_escape)

MODES: did a read of the help file. Sorry I don't get it. I have the right code in apps.py.
(from your code posted above for tmux)
Looks like it should open the file from ranger IN a pane in the same window by doing a split.
ULTRA-COOL.

Do I hit the number '2' then enter on the file?
Doing that opens the file as normal in urxvtc term. i did restart tmux.


UPDATE: figured what i'm to do though not working for me.

hit 'r' then hit '2'   still opens in vim not spilt pane in existing ranger tmux window.

maybe my .tmux.conf conflicts ?
or .vimrc ?

enjoyed the vim reformat for python command! nice.

Last edited by yvonney (2010-05-20 00:14:26)

Offline

#340 2010-05-19 23:47:33

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

hut wrote:

Oh, excellent, then just use this:

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        return tup("screen", "-t", c.file.basename, "vim", *c)

I entered this code with the "raise exception" part, but no result was returned so it seems like the code is not used by the program.

Offline

#341 2010-05-20 16:49:33

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

Re: Ranger, a textbased filemanager

jostber wrote:
hut wrote:

Oh, excellent, then just use this:

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        return tup("screen", "-t", c.file.basename, "vim", *c)

I entered this code with the "raise exception" part, but no result was returned so it seems like the code is not used by the program.

Well, thats bad. Here are some things you can try out:

1. ensure that you are editing the file "~/.ranger/apps.py"
2. try to create an empty file called "~/.ranger/__init__.py"
3. If ranger uses the file, it should create a "apps.pyo" (or apps.pyc) in ~/.ranger/. Does that happen?
4. ensure that ranger is not started with the "--clean" or "--confdir" switch.
5. If all fails, you'll have to edit the source directly in /path/to/ranger/defaults/apps.py

Last edited by hut (2010-05-20 16:50:26)


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

Offline

#342 2010-05-20 21:10:02

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

Thanks for your help. I tried the different steps, but can't still get it to work:

1. I verified this.
2. Created an init file, OK.
3. apps.pyo was created.
4. Verified this.
5. Tried to edit the source code as well, but nothing happened.

I believe ranger is using the apps.py file in ~/.ranger, because I have added some programs like "oocalc" in a section of the file and this works fine. Also if I add a syntax error in this file I get a traceback error. It just will not use the

return tup("screen", "-t", c.file.basename, "vim", *c)

, and insist on running vim plain instead.

Also if I add the code above at the start of the source file, I get this traceback error:

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ranger/__main__.py", line 205, in main
    load_settings(fm, ranger.arg.clean)
  File "/usr/lib/python2.6/site-packages/ranger/__main__.py", line 98, in load_settings
    from ranger.defaults import apps
  File "/usr/lib/python2.6/site-packages/ranger/defaults/apps.py", line 52, in <module>
    from ranger.defaults.apps import CustomApplications as DefaultApps
ImportError: cannot import name CustomApplications

I don't get this traceback error if I add the code at the start of the ~/.ranger/apps.py file.

Last edited by jostber (2010-05-20 21:14:24)

Offline

#343 2010-05-20 22:13:44

yvonney
Member
Registered: 2008-06-11
Posts: 671

Re: Ranger, a textbased filemanager

hut! regarding your tmux code that I have in apps.py and I do get the apps.pyo being created.
So, when scroll down in ranger over a text file, then hit 'r' then hit '2' the text file still opens up in
a urxvtc window, then I :q and back to ranger.

Maybe urxvt being differnt than xterm. Don't know. Though, typing '2' does what it should as far as triggering
your code I believe, as the file does open.
To get ranger, running in a tmux window, to open up the text file in a pane right in an beside the ranger window.
Your code has split in it so it's meant to.  it'll all work out at some point. just wanted to let you know as you use tmux 1.2.

from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
    def app_vim(self, c):
        if c.mode is 2:
            from ranger.ext.shell_escape import shell_escape
            return tup("tmux", "split-window", "-v", "vim " + "".join(shell_escape(name) for name in c))
        else:
            return tup("vim", *c)


UPDATE COMMENT: hitting r then any number as in r-0 r-1 r-2 r-3 all do the same as normal opening of file.
So maybe the code's not triggering at all for me so far.

Last edited by yvonney (2010-05-21 01:12:18)

Offline

#344 2010-05-20 22:20:15

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

Another option I thought of: Is it possible to bind the "!screen -t %s vim %f" to a key, more like a macro?

Offline

#345 2010-05-21 22:23:55

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

Re: Ranger, a textbased filemanager

Please upgrade ranger to ensure that you have the newest version.

It's really weird that the ~/.ranger/apps.py is used but you see no change whatsoever.
Try to rename app_vim to app_vimtest and run the file with rvimtest<enter>

Of course you can also add a key for "!screen -t %s vim %f", put that in ~/.ranger/keys.py

from ranger.api.keys import *
keymanager.map('browser', 'X', fm.open_console(cmode.OPEN, 'screen -t %s vim %f'))

You'll still have to press enter though. it's planned to add a function which executes commands right away


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

Offline

#346 2010-05-23 12:17:37

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

Adding a key as described above worked perfectly, thanks! I will also check out the other suggestion.

Offline

#347 2010-05-23 12:39:56

jostber
Member
Registered: 2010-05-18
Posts: 15

Re: Ranger, a textbased filemanager

I have upgraded Ranger to the most recent version with git, and if I add this code to the beginning of ~/.ranger/apps.py and run rvimtest on the file nothing happens. I have to run rvim to open the file, but it opens in the same window. If I add the code to /usr/lib/python2.6/site-packages/ranger/defaults/apps.py I get this traceback error and ranger
will not start:

Fatal: cannot import name CustomApplications
A traceback has been saved to /home/jostein/.ranger/traceback
Please include it in a bugreport.

Offline

#348 2010-05-25 10:52:53

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: Ranger, a textbased filemanager

Hi I saw that tagging was only there as a reminder. But is there a way to tag or select files in different directories, so I could move them altogether in another one ?

Offline

#349 2010-05-25 13:15:29

cmlr
Member
From: Rochester, NY, USA
Registered: 2007-04-18
Posts: 99

Re: Ranger, a textbased filemanager

Another key binding which should show up in the options at the bottom:  Pressing "p" shows the options "p once again" and "l".  The option "o" should also  show up.

Offline

#350 2010-05-25 19:38:20

Sirsurthur
Member
Registered: 2009-02-02
Posts: 124

Re: Ranger, a textbased filemanager

Hello Hut and thanks for ranger ! It's my main fm for few weeks now smile !

Since last git pull (commit    a71d6d9d1889d0eaecb7d2cf5ec4909fa75d1e88), I get

ranger
Traceback (most recent call last):
  File "/usr/bin/ranger", line 51, in <module>
    main()
  File "/usr/share/ranger/ranger/__main__.py", line 164, in main
    arg = parse_arguments()
  File "/usr/share/ranger/ranger/__main__.py", line 29, in parse_arguments
    from optparse import OptionParse
ImportError: cannot import name OptionParse

Thanks for your great work Hut !

I think that the bug is that the module name is OptionParser

Last edited by Sirsurthur (2010-05-25 19:49:47)

Offline

Board footer

Powered by FluxBB