summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2015-07-14 02:08:09 +0200
committerhut <hut@lepus.uberspace.de>2015-07-14 02:08:09 +0200
commitffc86e63f325a544d533b2a605e112ebc044f90e (patch)
tree57052f92bd9b12e4b2ce6e5fd1ac933cd1cdfc4c
parent2e5de116ba257d6a1dd3be2c0061640aa27c6648 (diff)
parenteed176768789208537b6bb8e97f08ef3d4b148fe (diff)
downloadranger-ffc86e63f325a544d533b2a605e112ebc044f90e.tar.gz
Merge branch 'ipc_plugin' of https://github.com/Vifon/ranger
-rw-r--r--examples/plugin_ipc.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/plugin_ipc.py b/examples/plugin_ipc.py
new file mode 100644
index 00000000..a9e79205
--- /dev/null
+++ b/examples/plugin_ipc.py
@@ -0,0 +1,45 @@
+# Tested with ranger 1.7.0 through ranger 1.7.*
+#
+# This plugin creates a FIFO in /tmp/ranger-ipc.<PID> to which any
+# other program may write. Lines written to this file are evaluated by
+# ranger as the ranger :commands.
+#
+# Example:
+#   $ echo tab_new ~/images > /tmp/ranger-ipc.1234
+
+import ranger.api
+
+old_hook_init = ranger.api.hook_init
+def hook_init(fm):
+    try:
+        # Create a FIFO.
+        import os
+        IPC_FIFO = "/tmp/ranger-ipc." + str(os.getpid())
+        os.mkfifo(IPC_FIFO)
+
+        # Start the reader thread.
+        try:
+            import thread
+        except ImportError:
+            import _thread as thread
+        def ipc_reader(filepath):
+            while True:
+                with open(filepath, 'r') as fifo:
+                    line = fifo.read()
+                    fm.execute_console(line.strip())
+        thread.start_new_thread(ipc_reader, (IPC_FIFO,))
+
+        # Remove the FIFO on ranger exit.
+        def ipc_cleanup(filepath):
+            try:
+                os.unlink(filepath)
+            except IOError:
+                pass
+        import atexit
+        atexit.register(ipc_cleanup, IPC_FIFO)
+    except IOError:
+        # IPC support disabled
+        pass
+    finally:
+        old_hook_init(fm)
+ranger.api.hook_init = hook_init
getwtxt/commit/main.go?id=c87acad59c4436554e60ab14870b77e49046c84a'>c87acad ^
bd5e602 ^
c87acad ^

bd2800a ^


c87acad ^

fb63b07 ^
bd5e602 ^
06cffd8 ^
bd5e602 ^


c87acad ^

06cffd8 ^
c87acad ^


893123c ^
bd5e602 ^
c87acad ^



bd5e602 ^
c87acad ^
893123c ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52