Skip to content

Instantly share code, notes, and snippets.

@nibrahim
Created October 18, 2016 11:27
Show Gist options
  • Save nibrahim/f358fed7201cf8ff7637ee8a2a122802 to your computer and use it in GitHub Desktop.
Save nibrahim/f358fed7201cf8ff7637ee8a2a122802 to your computer and use it in GitHub Desktop.
Pipe output of commands into Emacs
#!/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))
@nibrahim
Copy link
Author

Put this in your path somewhere, make it executable and then you can do stuff like ls | ep to put the output of ls into Emacs.

@bravegnu
Copy link

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