You are not logged in.
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.
Hm right, gonna add that
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 ?
As far as I know, this is not possible with the current version of ranger.
The tagged files are saved in ~/.ranger/tagged. You can easily write a script to move them all to one directory.
If none of the files contain spaces, this can be done with
cat ~/.ranger/tagged | xargs mv -t /the/target/directory
If they have spaces, I think you will have to work with readline.
I think that the bug is that the module name is OptionParser
Yeah that's just a typo, sorry for not testing before uploading the changes
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.
You can't put the same code in your ranger/defaults/apps.py.
In fact, the code in ~/.ranger/apps.py refers to your ranger/defaults/apps.py, in the line "from ranger.defaults.apps import ..."
Instead, just add the function (app_vimtest) without the first few lines to the existing class (CustomApplications in ranger/default/apps.py).
I still wonder why your ~/.ranger/apps.py is not working. Can you tell me what operating system/linux distro and python version you are using? Can you post the exact content of ~/.ranger/apps.py again?
Last edited by hut (2010-05-25 20:30:51)
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
My operating system is Suse 11.2 and I use Python 2.6.2. Here is my complete ~/.ranger/apps.py:
# Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com>#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This is the default ranger configuration file for filetype detection
and application handling.
You can place this file in your ~/.ranger/ directory and it will be used
instead of this one. Though, to minimize your effort when upgrading ranger,
you may want to subclass CustomApplications rather than making a full copy.
This example modifies the behaviour of "feh" and adds a custom media player:
#### start of the ~/.ranger/apps.py example
from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
def app_kaffeine(self, c):
return tup('kaffeine', *c)
def app_feh_fullscreen_by_default(self, c):
return tup('feh', '-F', *c)
def app_default(self, c):
f = c.file #shortcut
if f.video or f.audio:
return self.app_kaffeine(c)
if f.image and c.mode == 0:
return self.app_feh_fullscreen_by_default(c)
return DefaultApps.app_default(self, c)
#### end of the example
"""
from ranger.api.apps import *
from ranger.ext.get_executables import get_executables
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)
class CustomApplications(Applications):
def app_default(self, c):
"""How to determine the default application?"""
f = c.file
if f.basename.lower() == 'makefile':
return self.app_make(c)
if f.extension is not None:
if f.extension in ('pdf', ):
c.flags += 'd'
return self.either(c, 'evince', 'zathura', 'apvlv')
if f.extension in ('xml', ):
return self.app_editor(c)
if f.extension in ('html', 'htm', 'xhtml'):
return self.either(c, 'firefox', 'opera', 'elinks')
if f.extension in ('swf', ):
return self.either(c, 'firefox', 'opera')
if f.extension in ('xls', 'xlsx'):
return self.either(c, 'oocalc', 'gnumeric')
if f.extension in ('doc'):
return self.either(c, 'oowriter')
if f.extension in ('docx', ):
return self.either(c, 'oowriter')
if f.extension == 'nes':
return self.app_fceux(c)
if f.extension in ('swc', 'smc'):
return self.app_zsnes(c)
if f.mimetype is not None:
if INTERPRETED_LANGUAGES.match(f.mimetype):
return self.app_edit_or_run(c)
if f.container:
return self.app_aunpack(c)
if f.video or f.audio:
if f.video:
c.flags += 'd'
return self.either(c, 'mplayer', 'totem')
if f.image:
return self.either(c, 'feh', 'eye_of_gnome', 'mirage')
if f.document or f.filetype.startswith('text'):
return self.app_editor(c)
# ----------------------------------------- application definitions
# Note: Trivial applications are defined at the bottom
def app_pager(self, c):
return tup('less', *c)
def app_editor(self, c):
try:
default_editor = os.environ['EDITOR']
except KeyError:
pass
else:
parts = default_editor.split()
exe_name = os.path.basename(parts[0])
if exe_name in get_executables():
return tuple(parts) + tuple(c)
return self.either(c, 'vim', 'emacs', 'nano')
@depends_on(app_editor, Applications.app_self)
def app_edit_or_run(self, c):
if c.mode is 1:
return self.app_self(c)
return self.app_editor(c)
@depends_on('mplayer')
def app_mplayer(self, c):
if c.mode is 1:
return tup('mplayer', '-fs', *c)
elif c.mode is 2:
args = "mplayer -fs -sid 0 -vfm ffmpeg -lavdopts " \
"lowres=1:fast:skiploopfilter=all:threads=8".split()
args.extend(c)
return tup(*args)
elif c.mode is 3:
return tup('mplayer', '-mixer', 'software', *c)
else:
return tup('mplayer', *c)
@depends_on('feh')
def app_feh(self, c):
arg = {1: '--bg-scale', 2: '--bg-tile', 3: '--bg-center'}
c.flags += 'd'
if c.mode in arg:
return tup('feh', arg[c.mode], c.file.path)
if c.mode is 4:
return self.app_gimp(c)
if len(c.files) > 1:
return tup('feh', *c)
try:
from collections import deque
directory = self.fm.env.get_directory(c.file.dirname)
images = [f.path for f in directory.files if f.image]
position = images.index(c.file.path)
deq = deque(images)
deq.rotate(-position)
return tup('feh', *deq)
except:
return tup('feh', *c)
@depends_on('aunpack')
def app_aunpack(self, c):
if c.mode is 0:
c.flags += 'p'
return tup('aunpack', '-l', c.file.path)
return tup('aunpack', c.file.path)
@depends_on('make')
def app_make(self, c):
if c.mode is 0:
return tup("make")
if c.mode is 1:
return tup("make", "install")
if c.mode is 2:
return tup("make", "clear")
@depends_on('java')
def app_java(self, c):
def strip_extensions(file):
if '.' in file.basename:
return file.path[:file.path.index('.')]
return file.path
files_without_extensions = map(strip_extensions, c.files)
return tup("java", files_without_extensions)
@depends_on('totem')
def app_totem(self, c):
if c.mode is 0:
return tup("totem", *c)
if c.mode is 1:
return tup("totem", "--fullscreen", *c)
# Often a programs invocation is trivial. For example:
# vim test.py readme.txt [...]
# This could be implemented like:
# @depends_on("vim")
# def app_vim(self, c):
# return tup("vim", *c.files)
# Instead of creating such a generic function for each program, just add
# its name here and it will be automatically done for you.
CustomApplications.generic('fceux', 'elinks', 'wine',
'zsnes', 'javac')
# By setting flags='d', this programs will not block ranger's terminal:
CustomApplications.generic('opera', 'firefox', 'apvlv', 'evince',
'zathura', 'gimp', 'mirage', 'eog', flags='d')
# What filetypes are recognized as scripts for interpreted languages?
# This regular expression is used in app_default()
INTERPRETED_LANGUAGES = re.compile(r'''
^(text|application)/x-(
haskell|perl|python|ruby|sh
)$''', re.VERBOSE)
Last edited by jostber (2010-05-25 20:42:28)
Offline
The reason is: after you define CustomApplications, you define it again, overriding your custom version with the default version.
Change the content to only:
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)
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
Hello, first of all, thanks a lot for your great program! Been looking for a file manager with Miller columns for a while (found Dolphin, GWorkspace, a 4 years old Thunar hack... neither really did the work for me) and Ranger is definitely the most promising. Umm, I do have a couple suggestions - some of which have been mentioned already and I wasn't able to find solutions in the thread, so apologies if they have been addressed already!
1. Lazy horizontal scrolling? I must admit, it does feel a little weird when I click on the second column and it becomes the 2nd-to-last column, in my case at least. I'm no programmer, but from what I have gathered, it might require abandoning the 'second to last column = active' mechanism... so I guess I understand if you don't want to tackle it.
2. Custom "preview" for non-text files? As someone suggested, mediainfo, perhaps file - or set it just like you do with default applications in apps.py.
Offline
If I delete everything in ~/.ranger/apps.py and enter the code above, as well as entering the two last lines in ranger/default/apps.py it now works, but only if I use "rvim" on the file. It does not work when using Return on the file.
Should I delete everything except the code above in local apps.py or are there specific lines that should be deleted?
Offline
If I delete everything in ~/.ranger/apps.py and enter the code above, as well as entering the two last lines in ranger/default/apps.py it now works, but only if I use "rvim" on the file. It does not work when using Return on the file.
Should I delete everything except the code above in local apps.py or are there specific lines that should be deleted?
A look at app_default makes me think that you have to explicitly make this new function your default editor:
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)
app_editor = app_vim
---------
Hello, first of all, thanks a lot for your great program! Been looking for a file manager with Miller columns for a while (found Dolphin, GWorkspace, a 4 years old Thunar hack... neither really did the work for me) and Ranger is definitely the most promising. Umm, I do have a couple suggestions - some of which have been mentioned already and I wasn't able to find solutions in the thread, so apologies if they have been addressed already!
Thanks
1. Lazy horizontal scrolling? I must admit, it does feel a little weird when I click on the second column and it becomes the 2nd-to-last column, in my case at least. I'm no programmer, but from what I have gathered, it might require abandoning the 'second to last column = active' mechanism... so I guess I understand if you don't want to tackle it.
I thought about it for a while. It is indeed a little unusual that the thing you just clicked on suddenly moves away. But when using the keyboard, this doesn't bother me. So I won't work on that in the near future, though I'd accept patches.
2. Custom "preview" for non-text files? As someone suggested, mediainfo, perhaps file - or set it just like you do with default applications in apps.py.
Somebody already hacked in previews for images using libcaca. (It's also available on the caca branch of my git repo.)
It won't be too hard to add a mediainfo preview too.
Yet, how about a simple string option: you could set it to the path of an executable script which takes the filename as an argument and prints a preview to the stdout. This would override rangers default preview with whatever you like. Such a script would look like:
#!/bin/bash
type="$(file -Lb --mime-type "$1" | grep -o '^[^/]\+')"
case $type in
text )
cat "$1" ;;
image )
<some caca preview> "$1" ;;
video )
mediainfo-something "$1" ;;
esac
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
May I ask what the definitive code would be for tmux. For, opening a text file in a new tmux 'pane' -- same window though, -- a new pane in the tmux window that tmux runs ranger in. Hoping I just got it wrong on earlier attempts of there was an imcompatibility that may now be resolved. No concern of course if it doesn't happen for me for a while as things are great enough as they are. Would be cool to have a text file open up in a new pane with vim and have ranger still viewable in same window beside it. I use urxvtc.
The reason is: after you define CustomApplications, you define it again, overriding your custom version with the default version.
Change the content to only:
Code: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)
Offline
yvonney: That depends on what exactly you want.
Split the window vertically or horizontally?
Always do it whenever you open a file in vim? Or just as a new mode, to use with eg. 2<Enter>?
What should happen if you select multiple files and press enter?
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
from ranger.defaults.apps import CustomApplications as DefaultApps
from ranger.api.apps import *
class CustomApplications(DefaultApps):
def app_editor(self, c):
if 'TMUX' in os.environ:
from ranger.ext.shell_escape import shell_escape
return tup("tmux", "split-window", "-h",
"vim " + "".join(shell_escape(name) for name in c))
else:
return DefaultApps.app_vim(self, c)
This looks reasonable.
If you're in tmux, it opens vim in a new "sidebar", otherwise it just runs vim normally.
If you want a vertical split instead, change the "-h" to "-v".
Last edited by hut (2010-05-26 00:50:13)
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
That is amazing. Put the above code in apps.py deleted apps.pyo just in case. killed and restarted tmux/ranger et al.
now simply by hitting return on a file that ranger understands as vim-open-able and a pane opens up beside ranger.
This is SO amazingly useful for my requirements. I really like that after thinking with it for a few days it's cooler that it happened today!
Also thinking that add-on files like apps.py are great as ranger can stay lean.
Last edited by yvonney (2010-05-26 17:16:54)
Offline
jostber wrote:If I delete everything in ~/.ranger/apps.py and enter the code above, as well as entering the two last lines in ranger/default/apps.py it now works, but only if I use "rvim" on the file. It does not work when using Return on the file.
Should I delete everything except the code above in local apps.py or are there specific lines that should be deleted?
A look at app_default makes me think that you have to explicitly make this new function your default editor:
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) app_editor = app_vim
Now it works! I put the code above in ~/.ranger/apps.py, and the three last lines in ranger/default/apps.py. I also commented out these lines in local apps.py:
# def app_editor(self, c):
# try:
# default_editor = os.environ['EDITOR']
# except KeyError:
# pass
# else:
# parts = default_editor.split()
# exe_name = os.path.basename(parts[0])
# if exe_name in get_executables():
# return tuple(parts) + tuple(c)
#
# return self.either(c, 'vim', 'emacs', 'nano')
Thanks for all your help on this.
Offline
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?
I solved pt.2 by commenting out the first line in apps.py, and entered the second line below instead:
# images = [f.path for f in directory.files if f.image]
images = f.path
Last edited by jostber (2010-05-26 09:32:36)
Offline
I improved my zle widget for ranger integration:
integrate_ranger()
{
local before="$(pwd)"
ranger $before <$TTY
local after="$(grep \^\' ~/.ranger/bookmarks)"
after[1,2]=
if [[ $before != $after ]]; then
cd $after
print "ranger: $before -> $after"
fi
zle redisplay
precmd
}
Offline
This is what I use to view the directory, starting at the selected image:
[~/.ranger/apps.py]
class CustomApplications(DefaultApps):
def app_feh(self, c):
cwd = self.fm.env.cwd.path
return tup('feh', cwd, '--start-at', *c)
def app_default(self, c):
f = c.file #shortcut
if f.image:
return self.app_feh(c)
return DefaultApps.app_default(self, c)
Offline
I solved pt.2 by commenting out the first line in apps.py, and entered the second line below instead:
Btw, that is fixed in the newest version already.
I improved my zle widget for ranger integration:
integrate_ranger() { local before="$(pwd)" ranger $before <$TTY local after="$(grep \^\' ~/.ranger/bookmarks)" after[1,2]= if [[ $before != $after ]]; then cd $after print "ranger: $before -> $after" fi zle redisplay precmd }
*steals some ideas for own .bashrc*
EDIT:
Sure that this doesn't break when either path contains spaces?
I'd put "" around each $before and $after (except in the print)
This is what I use to view the directory, starting at the selected image:
[~/.ranger/apps.py]
class CustomApplications(DefaultApps): def app_feh(self, c): cwd = self.fm.env.cwd.path return tup('feh', cwd, '--start-at', *c) def app_default(self, c): f = c.file #shortcut if f.image: return self.app_feh(c) return DefaultApps.app_default(self, c)
Nice, didn't know of the --start-at option of feh. (and that you can view whole directories easily.) This makes things much easier
Last edited by hut (2010-05-26 22:41:12)
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
EDIT:
Sure that this doesn't break when either path contains spaces?
I'd put "" around each $before and $after (except in the print)
No, zsh doesn't split words on variable expansion unless SH_WORD_SPLIT is set. SH_WORD_SPLIT can be set temporarily by using $=foo instead of $foo, but in most cases it's better to use an array, they are far more powerful.
Offline
Information about the progress:
1. I'm implementing easily extendable previews. Ranger will just call an external program, pass the filename as an argument and use its output as the preview. That program can call stuff like img2txt, highlight, pygmentize, mediainfo or whatever you want. It would look similar to the apps.py, but you would require no knowledge of ranger internals to edit it since it runs independently.
2. A contributor is trying to get directories loading faster by rewriting the related functions. Let's see how far this gets. I still hope ranger will be as fast as vifm some day
3. I want to make configuration files more simple. Throw in your suggestions!
See also: http://lists.nongnu.org/archive/html/ra … 00005.html
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
Nice, especially 2. The slow directory loading is my biggest problem with ranger.
1. Adhere to the unix philosophy and "do one thing but do it well"
=> Ranger is a file manager, not a file launcher.
Remove apps.py, leave launching of programs to another program.
I strongly agree. It would be great to write a script that takes a file as an argument and opens it with the correct program based on mime type and make all my programs use that script.
Last edited by JohannesSM64 (2010-06-05 13:06:09)
Offline
A little off-topic: I would very much like to replace vim's internal file explorer with ranger. Does anyone know if there is a way to do that?
Offline
I agree about removing apps.py as well - imo ranger should honor the existing mimetype associations. Maybe ranger should require xyne's mimeo.
@Franek, yeah that would be awesome. Vim can be scripted with python, so it should be possible. You might want to check out nerdtree.
Offline
@vim integration:
No idea, but I doubt that it's trivial :-)
I'll be there for consulting if someone wants to try it.
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
It's worth hundreds of beers. Hopefully Ranger isn't released under a beerware license!
##hippie irc.freenode.net
Offline
Version 1.1.0 (stable) is out.
For those who regularily updated: this is nothing new, just what you've been testing all along.
For those who didn't: consider upgrading now =P
"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users
Offline
Anyone think of a way to change the PS1 to indicate that the shell was started from within Ranger (via 'S') ? I find myself entering the shell for a bit, walking away for awhile and then inadvertently starting a second ranger instance instead of C-d to get back to the first one.
Thanks!
Scott
Offline
make Ranger's S set os.environ['PS1'], and make your shell rc a) not set PS1 if it's already set or b) append to it
Offline