You are not logged in.
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
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
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
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
Using du (type d then u) ?!
That works, thanks.
Offline
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
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
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
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.
Offline
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
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
I can't see an obvious cause but I'll try and find a cure.
That would be great! Thank you in advance.
Offline
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
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
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
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
Hello, Veedrac.
Seems it works! I appreciate for your help very much!
Offline
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
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
Thank you, Army.
Offline
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:
How would I make ranger run:
search_file("", offset=0)
...on start up, or fix the odd default behavior of the 'n' key?
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?
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
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
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')
Offline
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
.. and please remove the zombies left when child exits.
Offline