diff options
author | hut <hut@lepus.uberspace.de> | 2015-04-13 12:49:49 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2015-04-13 12:49:49 +0200 |
commit | c0f2fc72eccb4127fba5f48ce4b422487d6ec752 (patch) | |
tree | 025f72dde6f7a7e5cdca82637da4e5dcef0ddd62 /examples/plugin_hello_world.py | |
parent | a9bbdc440c2ea33ccc4470e00949ffa16ce2300e (diff) | |
download | ranger-c0f2fc72eccb4127fba5f48ce4b422487d6ec752.tar.gz |
moved "doc/examples" to "examples" for more visibility
Diffstat (limited to 'examples/plugin_hello_world.py')
-rw-r--r-- | examples/plugin_hello_world.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/plugin_hello_world.py b/examples/plugin_hello_world.py new file mode 100644 index 00000000..a803e21b --- /dev/null +++ b/examples/plugin_hello_world.py @@ -0,0 +1,23 @@ +# Compatible with ranger 1.6.* +# +# 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 safe. + return old_hook_ready(fm) + +# Finally, "monkey patch" the existing hook_ready function with our replacement: +ranger.api.hook_ready = hook_ready |