Last active
June 1, 2017 22:57
-
-
Save louisswarren/21ff57fad7fb7e2a4f1a71814c375a34 to your computer and use it in GitHub Desktop.
A clarinet is a pipe with a reed; clarinet.py reads from a named pipe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import sys | |
import textwrap | |
import time | |
def usage(): | |
print(textwrap.dedent(""" | |
Usage: {} <pipepath> | |
Create a named pipe, send its contents to stdout forever. | |
Supplied pipe path must not exist. | |
Warning: supplied pipe path will be deleted after a keyboard interrupt. | |
""".format(sys.argv[0])).strip()) | |
def read_loop(f): | |
while True: | |
data = f.read() | |
if data: | |
sys.stdout.write(data) | |
sys.stdout.flush() | |
else: | |
time.sleep(0.1) | |
def make_pipe(pipe_fname): | |
try: | |
os.mkfifo(pipe_fname) | |
except OSError as e: | |
print("Failed to create named pipe {}".format(pipe_fname)) | |
print("Error:", e) | |
sys.exit(1) | |
def main(pipe_fname): | |
make_pipe(pipe_fname) | |
try: | |
with open(pipe_fname) as fifo: | |
read_loop(fifo) | |
except KeyboardInterrupt: | |
print() | |
finally: | |
os.unlink(pipe_fname) | |
if __name__ == '__main__': | |
if len(sys.argv) == 2: | |
main(sys.argv[1]) | |
else: | |
usage() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case:
In
~/.vim/ftplugin/scheme.vim
:Then start minlog with (assuming your scheme implementation is guile)
Vim will write the commands to execute into the named pipe, and clarinet will pipe them into guile. Minlog without emacs!