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 ...
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 ...
7
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 ...
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): ...
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, ...
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-...
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-...
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 ...
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-...
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-...
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 ...
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:
~/...
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'."
(...
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 ...
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 ...
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-...
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....
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 ...
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 &...
3
votes
Persistent shell-command history
I'm sure that savehist can manage this, here is my setup:
;; Save sessions history
(setq savehist-save-minibuffer-history 1)
(setq savehist-additional-variables
'(kill-ring search-ring regexp-...
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:
~/Documents ...
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 ...
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 ...
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/...
3
votes
Accepted
How to run commands locally even when on tramp?
The point is default-directory. If it is local, your command runs locally. So do something like
(let ((default-directory "/"))
(do your stuff))
3
votes
Accepted
Use basename of the file
To expanding on @NickD's answer, I like to do these kind of shell operations with compile so I can take advantage of the instantly visible window with the "compile" command's output. Taking ...
3
votes
Accepted
Why is my simple use of shell-command to change a global keybinding in Linux not working?
When including double-quotes inside a string, be sure to "escape" them, which in Emacs is accomplished with a backslash, otherwise the string representing your command will end prematurely. (...
3
votes
pass arguments in call-process as key/value
The last argument to apply must be a list, see the documentation (emphasis mine)
Call FUNCTION with our remaining args, using our last arg as list of args.
You can group all arguments passed to the ...
2
votes
Make shell-command / async-shell-command respect carriage return?
My question is how can I make the output look like the way similar to shell output (i.e. \r moves to the begin of a line, further output overwrites previous one, and \n switches to a newline).
If you ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
shell-command × 150shell × 26
process × 9
async × 9
dired × 7
eshell × 7
microsoft-windows × 6
subprocess × 6
call-process × 6
key-bindings × 5
tramp × 5
linux × 5
git × 4
region × 4
copy-paste × 4
bash × 4
org-mode × 3
org-babel × 3
init-file × 3
spacemacs × 3
terminal-emacs × 3
sudo × 3
python × 2
evil × 2
window × 2