summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-12-03 23:26:19 +0100
committerhut <hut@lavabit.com>2012-12-04 23:32:21 +0100
commit32a80ea727d940a5f359a135a4b8d83b77fa0bca (patch)
tree756d40fd432a288bbf8aa4c090a1d12ba29f7bda /examples
parentca1a5d21e6564c022b810c4f52daf61fc4f3ea30 (diff)
downloadranger-32a80ea727d940a5f359a135a4b8d83b77fa0bca.tar.gz
added examples/plugin_hello_world.py
Diffstat (limited to 'examples')
-rw-r--r--examples/plugin_hello_world.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/plugin_hello_world.py b/examples/plugin_hello_world.py
new file mode 100644
index 00000000..187f428e
--- /dev/null
+++ b/examples/plugin_hello_world.py
@@ -0,0 +1,21 @@
+# This is a sample plugin that displays "Hello World" in ranger's console after
+# it started.
+
+# We are going to extend the hook "ranger.api.hook_ready", so first we need
+# to import ranger.api:
+import ranger.api
+
+# Save the previously existing hook, because maybe another module already
+# extended that hook and we don't want to lose it:
+old_hook_ready = ranger.api.hook_ready
+
+# Create a replacement for the hook that...
+def hook_ready(fm):
+  # ...does the desired action...
+  fm.notify("Hello World")
+  # ...and calls the saved hook.  If you don't care about the return value, simply
+  # return the return value of the previous hook to be on the safe side.
+  return old_hook_ready(fm)
+
+# Finally, "monkey patch" the existing hook_ready function with our replacement:
+ranger.api.hook_ready = hook_ready