-
-
Save nibrahim/f358fed7201cf8ff7637ee8a2a122802 to your computer and use it in GitHub Desktop.
Pipe output of commands into Emacs
This file contains hidden or 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 python | |
import sys | |
import subprocess | |
PIPE_BUFFER_NAME="*piped*" | |
def execute_command(c): | |
cmd = ["/usr/bin/emacsclient", "-n", "-e", c] | |
p = subprocess.Popen(cmd, stdout=subprocess.DEVNULL) | |
p.wait() | |
execute_command('(switch-to-buffer (get-buffer-create "{}"))'.format(PIPE_BUFFER_NAME)) | |
for i in sys.stdin: | |
i = i.replace('"', '\\"') | |
execute_command('(with-current-buffer "{}" (insert "{}"))'.format(PIPE_BUFFER_NAME, i)) |
Useful as a pager for git, when you are using git commands from shell-mode.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this in your path somewhere, make it executable and then you can do stuff like
ls | ep
to put the output ofls
into Emacs.