summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2015-02-17 23:12:02 +0100
committerhut <hut@lepus.uberspace.de>2015-02-17 23:12:02 +0100
commit54dedc056f67e6db85517a2f4c94675a29f64b5d (patch)
tree6627125053c51ee284cc7520d840f342695382ec
parent1ad66d5b5f693904e6a552737c80bb6d0cad44ec (diff)
downloadranger-54dedc056f67e6db85517a2f4c94675a29f64b5d.tar.gz
added a sample commands.py
-rw-r--r--ranger/config/commands_sample.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/ranger/config/commands_sample.py b/ranger/config/commands_sample.py
new file mode 100644
index 00000000..e06db38a
--- /dev/null
+++ b/ranger/config/commands_sample.py
@@ -0,0 +1,53 @@
+# This is a sample commands.py.  You can add your own commands here.
+#
+# Please refer to commands_full.py for all the default commands and a complete
+# documentation.  Do NOT add them all here, or you may end up with defunct
+# commands when upgrading ranger.
+
+# You need to import ranger.api.commands to get the Command class:
+from ranger.api.commands import *
+# Import any other python modules as needed:
+import os
+
+# Any class that is a subclass of "Command" will be integrated into ranger as a
+# command.  Try typing ":my_edit<ENTER>" in ranger!
+class my_edit(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.
+    """:my_edit <filename>
+
+    Opens the specified file in vim
+    """
+
+    # The execute method is called when you run this command in ranger.
+    def execute(self):
+        # self.arg(1) is the first (space-separated) argument to the function.
+        # This way you can write ":my_edit somefilename<ENTER>".
+        if self.arg(1):
+            # self.rest(1) contains self.arg(1) and everything that follows
+            target_filename = self.rest(1)
+        else:
+            # self.fm is a ranger.core.filemanager.FileManager object and gives
+            # you access to internals of ranger.
+            # self.fm.thisfile is a ranger.container.file.File object and is a
+            # reference to the currently selected file.
+            target_filename = self.fm.thisfile.path
+
+        # This is a generic function to print text in ranger.  
+        self.fm.notify("Let's edit the file " + target_filename + "!")
+
+        # Using bad=True in fm.notify allows you to print error messages:
+        if not os.path.exists(target_filename):
+            self.fm.notify("The given file does not exist!", bad=True)
+
+        # 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.
+        self.fm.edit_file(target_filename)
+
+    # 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()