mirror of
https://github.com/jchook/ranger-zoxide.git
synced 2026-01-26 17:37:12 +08:00
Merge pull request #8 from rccavalcanti/add_interactive
Add interactive mode
This commit is contained in:
commit
2958bb7d17
2 changed files with 23 additions and 4 deletions
12
README.md
12
README.md
|
|
@ -9,6 +9,12 @@ Easily jump between commonly visited directories by running this in ranger:
|
|||
:z <partial-name>
|
||||
```
|
||||
|
||||
Or use interactive mode:
|
||||
|
||||
```
|
||||
:zi <partial-name>
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Very simple & fast thanks to zoxide
|
||||
|
|
@ -43,6 +49,12 @@ directories. Simply add a binding to your `~/.config/ranger/rc.conf` file:
|
|||
map cz console z%space
|
||||
```
|
||||
|
||||
Or for interactive use:
|
||||
|
||||
```
|
||||
map cz zi
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
- [ranger-zjumper](https://github.com/ask1234560/ranger-zjumper).
|
||||
|
|
|
|||
15
__init__.py
15
__init__.py
|
|
@ -13,6 +13,7 @@ def hook_init(fm):
|
|||
process.wait()
|
||||
|
||||
fm.signal_bind("cd", zoxide_add)
|
||||
fm.commands.alias("zi", "z -i")
|
||||
return hook_init_prev(fm)
|
||||
|
||||
|
||||
|
|
@ -26,17 +27,22 @@ class z(ranger.api.commands.Command):
|
|||
"""
|
||||
def execute(self):
|
||||
results = self.query(self.args[1:])
|
||||
if not results:
|
||||
return
|
||||
|
||||
if os.path.isdir(results[0]):
|
||||
self.fm.cd(results[0])
|
||||
|
||||
def query(self, args):
|
||||
try:
|
||||
p = Popen(
|
||||
["zoxide", "query"] + self.args[1:],
|
||||
stdout=PIPE,
|
||||
stderr=PIPE
|
||||
p = self.fm.execute_command("zoxide query {}".format(" ".join(self.args[1:])),
|
||||
stdout=PIPE
|
||||
)
|
||||
stdout, stderr = p.communicate()
|
||||
|
||||
if not stdout:
|
||||
return None
|
||||
|
||||
if p.returncode == 0:
|
||||
output = stdout.decode("utf-8").strip()
|
||||
if output:
|
||||
|
|
@ -52,3 +58,4 @@ class z(ranger.api.commands.Command):
|
|||
def tab(self, tabnum):
|
||||
results = self.query(self.args[1:])
|
||||
return ["z {}".format(x) for x in results]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue