From af84a3d580a8f715c92ea3efa2ea8b259390935c Mon Sep 17 00:00:00 2001 From: Rafael Cavalcanti Date: Sun, 15 Aug 2021 11:28:37 -0300 Subject: [PATCH 1/3] Allow running interactively with -i --- __init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 4e4668f..2c1777d 100644 --- a/__init__.py +++ b/__init__.py @@ -26,17 +26,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: From 4f97e03f60e582ba2cb20378ae9e839be7d7a2f6 Mon Sep 17 00:00:00 2001 From: Rafael Cavalcanti Date: Sun, 15 Aug 2021 11:48:31 -0300 Subject: [PATCH 2/3] Add zi as alias --- __init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/__init__.py b/__init__.py index 2c1777d..fedc500 100644 --- a/__init__.py +++ b/__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) @@ -57,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] + From 7a939a843e682ff2f816266d10e7ed10829617f0 Mon Sep 17 00:00:00 2001 From: Rafael Cavalcanti Date: Sun, 15 Aug 2021 11:49:27 -0300 Subject: [PATCH 3/3] Add interactive mode to README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f5e447f..79fd590 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ Easily jump between commonly visited directories by running this in ranger: :z ``` +Or use interactive mode: + +``` +:zi +``` + ## 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).