summary refs log tree commit diff stats
path: root/lib/std/varints.nim
Commit message (Expand)AuthorAgeFilesLines
* Make unused code into actual test, replace echo with doassert (#13952)Juan Carlos2020-04-111-33/+0
* fix conversions to uint in varints.nim (#12564)Arne Döring2019-11-041-22/+22
* last stdlib cleanupsAraq2019-09-211-1/+3
* varints module: critical bugfixAndreas Rumpf2018-06-221-1/+8
* added experimental undokumented std/varints moduleAndreas Rumpf2018-05-191-0/+145
# 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