Skip to main content
13 votes

Get output of external command in the buffer

Actually the shortest way of doing it is to use shell-command with a prefix argument. This is mapped to C-u M-!. The C-u prefix argument changes the standard M-! to insert the output in the current ...
dfeich's user avatar
  • 1,914
11 votes
Accepted

How do i change the default shell for shell-command

You need to change the option shell-file-name. (setenv "SHELL" "/bin/bash") This doesn't work since Emacs is already running thus it's too late, Emacs initializes shell-file-name according to ...
xuchunyang's user avatar
  • 14.7k
11 votes
Accepted

Run elisp when `async-shell-command` is done

You can specify the output buffer for async-shell-command. The shell runs as a process of the output buffer. You can get that process with get-buffer-process. Define your own process sentinel for the ...
Tobias's user avatar
  • 33.5k
8 votes
Accepted

Run elisp from command line in running emacs

You can either wrap your two forms in a progn: emacsclient --no-wait --eval '(progn (message "hi") (setq abc 123))' Or you can send them separately: emacsclient --no-wait --eval '(message "hi")' '(...
Dan's user avatar
  • 33.3k
7 votes
Accepted

How to run sudo commands using shell-command?

When default-directory points to a sudo-ized path, shell-command uses this environment. Try (let ((default-directory "/sudo::")) (shell-command "ls")) The password will be asked interactively.
Michael Albinus's user avatar
7 votes
Accepted

How to run a previous unique command in an Emacs shell (without repeats)?

The shell you get from M-x shell is based on comint, so you can set comint-input-ignoredups to t in order to get the behaviour you want. The help even mentions bash: comint-input-ignoredups is a ...
Omar's user avatar
  • 4,842
6 votes
Accepted

When does shell-command-on-region actually pass the region to the command?

Why is the region passed to the command in the first example and not in the second and third one? The region is passed in all three cases; but if the command you pass it to does nothing with its ...
phils's user avatar
  • 52.4k
6 votes
Accepted

async-shell-command: run COMMAND without displaying the output

Try this: (add-to-list 'display-buffer-alist '("*Async Shell Command*" display-buffer-no-window (nil))) The buffer is still created and it still gets the output of the command (or the error output): ...
NickD's user avatar
  • 32.5k
5 votes
Accepted

How to mix eshell and elisp code

For something simple, shell-command-to-string may suffice. For something more complicated where the output needs to be modified, searched, etc., then something more elaborate may needed e.g., set-...
lawlist's user avatar
  • 19.4k
5 votes
Accepted

How to open system's command line at the directory of the current buffer?

You need to use start cmd to get a new terminal window. Use M-& (async-shell-command) to avoid blocking Emacs. This creates a useless *Async Shell Command* buffer, you can use the start-process-...
npostavs's user avatar
  • 9,233
5 votes

How to make "shell-command-on-region" display output as a message on a non-zero exit code?

I would suggest considering to report a bug. Personally I'm fine with it, since it's easy to fix via C-/ (undo). To do what you want right now, my first thought is to advice shell-command-on-region, ...
xuchunyang's user avatar
  • 14.7k
5 votes

Split command line into a list of arguments

Does this do what you want? (split-string-and-unquote "program arg1 arg2 \"long argument with spaces\" \"arg\"3") There seemed to be an error in your string with an unmatched \" at the end that ...
John Kitchin's user avatar
5 votes
Accepted

Almost working smoothly attempt to get terminal Emacs to copy to clipboard

I'm also a loyal emacs-nw user, and have struggled with this over the recent emacs versions. What works for me, and without any need to C-g, follows. Note that it has a safety check that is linux-...
user1404316's user avatar
5 votes
Accepted

Send content of region or current line to a tmp file, then execute shell script with filename as argument

If your ~/dotfiles/rundo.sh accepts stdin as input, like many other commands such as grep/wc/bash/python, to run a command with the region as stdin, simply run M-| ~/dotfiles/rundo.sh (M-| runs shell-...
xuchunyang's user avatar
  • 14.7k
5 votes

How to pipe large files through fold before opening?

Have emacs read from stdin device and insert contents into *scratch* buffer. $ fold -w80 myfile | emacs --insert /path/to/stdin Note: You will need to update /path/to/stdin path e.g. $ fold -w80 ...
Melioratus's user avatar
  • 4,718
4 votes
Accepted

Is there a package to send a piece of text to shell and get the result back?

Possibly, but there's no need to install a package for this; it's built in. The command shell-command-on-region (bound to M-| by default) prompts for and then executes a shell command, sending it ...
db48x's user avatar
  • 18.8k
4 votes

Command to Run (Eval) "Hello World" in ELISP on Eshell?

The one word you request can also be just a dot .. After running that command you get: ~/Documents $ . hello.el Hello World ~/Documents $ If this is too strange for you you can also use: ~/...
Tobias's user avatar
  • 33.5k
4 votes
Accepted

Asynchronous version of shell-command-on-region?

Something in this spirit should do the trick. I tried it with espeak under Ubuntu; I guess it would work with say as well. (defun my-read-words-on-region () "Send the region to `espeak'." (...
Nsukami _'s user avatar
  • 6,631
4 votes

Differences between cmdproxy.exe and cmd.exe

I just found this: Proxy shell designed for use with Emacs on Windows 95 and NT. [...] The main function is simply to process the "-c string" option in the way /bin/sh does, since the standard ...
antonio's user avatar
  • 1,832
4 votes
Accepted

Run current line or selection in shell then insert result in Emacs buffer (Acme workflow)

M-| (M-x shell-command-on-region) runs a shell command using the region as stdin, display the output in the echo area, with a prefix arg, replace the region with the output. Unlike your shell in a ...
xuchunyang's user avatar
  • 14.7k
4 votes

Use basename of the file

Write your own function to prepare the command string as you want it and then pass it to shell-command for execution: (defun pandoc-it () (interactive) (let* ((basename (file-name-base (buffer-...
NickD's user avatar
  • 32.5k
4 votes

Running and viewing results from bash scripts

Did you try the shell-command command? If you don’t know what it does, run C-h f shell-command to see the help for it: shell-command is an interactive and byte-compiled function defined in simple.el....
db48x's user avatar
  • 18.8k
3 votes

Refresh `async-shell-command` buffer

You can try something like (guaranteed untested): (defvar-local shell-command--command nil) (advice-add 'async-shell-command :after #'my-set-revert-buffer) (defun my-set-revert-buffer (command &...
Stefan's user avatar
  • 26.6k
3 votes

Command to Run (Eval) "Hello World" in ELISP on Eshell?

You asked: A file (message "Hello World") saved as 'hello.el'. Now, how to run (evaluate) this file on Eshell? ~/Documents $ ....... hello.el I just fill in the command at the dots: ~/...
Tobias's user avatar
  • 33.5k
3 votes

Get output of external command in the buffer

Here's a very simple function that will insert the shell command's output at point it the current buffer. Note that it makes no effort to do error checking, but you can adapt it to do so if needed: (...
Dan's user avatar
  • 33.3k
3 votes

Shell Command with bash script and arguements

As YoungFrog mentions, you must quote the file name. Otherwise, the code fails if, for instance, the file name contains whitespaces. You might explicitely check that the current buffer is visiting a ...
Tino's user avatar
  • 430
3 votes
Accepted

Making custom shell command function have popup buffer showing std-out

start-process has an optional argument to generate an output buffer. A set-process-sentinel may be used in conjunction with start-process to monitor the termination of a process, so that certain ...
lawlist's user avatar
  • 19.4k
3 votes
Accepted

Sudo caching on compilation mode

I suppose you are using Tramp's sudo method to run the command with root permissions from Emacs. With a very recent snapshot of Tramp 2.4.1-pre (or 27.0.50), there is a new configuration parameter to ...
Michael Albinus's user avatar
3 votes

Emacs unable to execute shell commands despite them being in the Emacs shell PATH

Solved it: it was because Emacs was installed as a flatpak. For some reason, this mean the Emacs shell had many differences. I wasn't able to cd into certain folders. Other folders didn't exist: /usr/...
Russ Phelan's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible