summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2026-02-21 11:08:07 +0100
committerache <ache@ache.one>2026-02-21 11:08:07 +0100
commit14ce5a2374e0037906715f6b9caf63da2ee3d5b2 (patch)
treeb8b7e6c1774bc9901628a83861813058dc3427e2
parentAdd a comment on pillow as a dependency (diff)
feat: Add a feature to z into a folder
-rw-r--r--commands.py34
-rwxr-xr-xrc.conf1
2 files changed, 35 insertions, 0 deletions
diff --git a/commands.py b/commands.py
index 2df405f..e838662 100644
--- a/commands.py
+++ b/commands.py
@@ -56,3 +56,37 @@ class my_edit(Command):
# This is a generic tab-completion function that iterates through the
# content of the current directory.
return self._tab_directory_content()
+
+
+# Any class that is a subclass of "Command" will be integrated into ranger as a
+# command. Try typing ":my_edit<ENTER>" in ranger!
+class z(Command):
+ # The so-called doc-string of the class will be visible in the built-in
+ # help that is accessible by typing "?c" inside ranger.
+ """:z <fuzzy_filename>
+
+ A sample command for demonstration purposes that opens a file in an editor.
+ """
+
+ # The execute method is called when you run this command in ranger.
+ def execute(self):
+ import os.path
+ # This executes a function from ranger.core.acitons, a module with a
+ # variety of subroutines that can help you construct commands.
+ # Check out the source, or run "pydoc ranger.core.actions" for a list.
+
+ fuzzy_file = self.arg(1)
+ command = ["zoxide", "query", fuzzy_file]
+
+ if "%" in command:
+ command = self.fm.substitute_macros(command, escape=True)
+
+ destination = subprocess.check_output(command).decode("utf8").strip()
+ self.fm.cd(destination)
+
+ # The tab method is called when you press tab, and should return a list of
+ # suggestions that the user will tab through.
+ def tab(self):
+ # This is a generic tab-completion function that iterates through the
+ # content of the current directory.
+ return self._tab_directory_content()
diff --git a/rc.conf b/rc.conf
index 568c7f8..d713236 100755
--- a/rc.conf
+++ b/rc.conf
@@ -439,6 +439,7 @@ map oE chain set sort=extension; set sort_reverse=True
map dc get_cumulative_size
# Settings
+map Z console z%space
map zc toggle_option collapse_preview
map zd toggle_option sort_directories_first
map zh toggle_option show_hidden