[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Ranger-users] explorer mode
From: |
Joshua Landau |
Subject: |
Re: [Ranger-users] explorer mode |
Date: |
Fri, 26 Oct 2012 19:53:34 +0100 |
On 25 October 2012 11:08, Eduardo Suarez-Santana <address@hidden> wrote:
Is there a classic explorer mode? That is, I type the first letters of the filename and then it gets selected. 'Enter' to go forward, 'Backspace' to go back.
'f' does something similar, but it's not the same.
I've implemented and often use something almost as good - not quite, but close - called "travel".
It's a little old, so it doesn't do quite what it used to in a few circumstances. However, it works thusly:
- Press key-binding to enter travel mode
- Type to filter dynamically
- When there is only exactly one file left:
- If it is a directory, enter it
- Else, run it (default mode)
- Press TAB to move forward one file
- Press ENTER to run current file, or enter directory
- Press ESC to quit
- If the filter is "..", go back a directory
Entering directories does not quit, but just resets the filter.
To try it, use this code (put it in your "~/.config/ranger/commands.py") and add it to your key-bindings somewhere.
# Code goes here:
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:
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 = self.rest(1)
self.fm.set_filter(arg)
self.fm.reload_cwd()
if arg == ".":
return
if arg == "..":
self.special = ".."
return self.execute()
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 self.execute()
def tab(self):
self.fm.move(down=1)
else:
self.fm.move(to=0)