Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a process and get the result in clipboard (or kill ring) with elisp/emacs

Tags:

elisp

I use the following code to run "ls -l ./" and get the result in scratch buffer.

(start-process "my-process" "*scratch*" "ls" "-l" "./")
  • How can I get the result in clipboard or something (kill ring or whatever) so that I can easily copy the result whenever necessary?
like image 953
prosseek Avatar asked Feb 27 '23 09:02

prosseek


2 Answers

You can adjust this to your liking:

(kill-new (shell-command-to-string "ls -l ."))

The call to kill-new will put the string from shell-command-to-string on the kill ring.

like image 161
Trey Jackson Avatar answered Apr 29 '23 06:04

Trey Jackson


shell-command (bound to M-!) runs a shell command and puts its output in *Shell Command Output*. Given an argument (eg: M-1 M-!) it will put the results in the current buffer.

A little more information is available on the page ExecuteExternalCommand on the Emacs wiki

like image 36
Bryan Oakley Avatar answered Apr 29 '23 05:04

Bryan Oakley