Questions tagged [shell-command]

is for executing shell commands from Emacs (the default key binding is `M-!`). Shell output is shown in the echo area if it fits, in buffer `*Shell Command Output*` otherwise. Emacs comes with many supporting facilities for executing shell commands, including interactive execution, selective execution on a region, history cycling, directory tracking, connecting to serial ports, emulator options, and specifying remote hosts.

Filter by
Sorted by
Tagged with
0 votes
3 answers
57 views

Keyboard shortcut for running shell commands

I want to trigger running makefile from inside emacs. I followed this link and added to (defun set-exec-path-from-shell-PATH () (let ((path-from-shell (replace-regexp-in-string ...
1 vote
1 answer
43 views

Gnus cannot start external w3m: no such file or directory

while I am using Emacs as an editor for years on my Macbook (OSX 10.13), I only recently started again to launch external commands by using Gnus. While this answer helped me to fix calls to uncompface,...
  • 155
3 votes
1 answer
44 views

How to run a buffer/region with shell commands as root user?

I need to copy-paste a bunch of shell commands to emacs and run them as root/sudo. How do I do it? For instance, while configuring samba, I come across this instruction from the documentation: Become ...
0 votes
1 answer
53 views

Different behavior between M-! and a terminal?

I'm writing a major mode to interface with a popular but clunky Monte Carlo program. I've also written a script that makes the interface a little more tolerable, and have written the following simple ...
  • 113
1 vote
0 answers
36 views

shell-command changing the behavior of my program

Consider the following C code: #include <stdio.h> #include <unistd.h> int main() { printf("PID: %d\n", getpid()); fork(); } This should output the PID of the process and ...
  • 111
0 votes
1 answer
22 views

`shell-command` output not working when in a function

I have (shell-command-to-string "ls") which works just fine but when I put it in a function it breaks as (defun testing () (shell-command-to-string "ls") ) outputs nil. I am ...
0 votes
1 answer
46 views

How to bind a terminal command to a key for python code autoformatting using autopep8

I'd like to autoformat my python code from the buffer that contains it with a key. I was looking at this tutorial. One can autoformat the code from the terminal with the command: autopep8 --in-place --...
1 vote
1 answer
45 views

Using shell-command-on-region with TRAMP

I like to use shell-command-on-region for pretty printing a selected region of code with prettier. After selecting a region, I type C-u M-| and then I use prettier --parser ruby as the shell command. ...
0 votes
1 answer
53 views

How do I set a restclient variable by calling a function?

This is probably just a reflection of my weak elisp skills but when I try to create a restclient variable via a function call: :uid := (shell-command "uuidgen" t) It does not assign the ...
  • 115
3 votes
3 answers
61 views

Use basename of the file

When I am done editing myfile.tex, I M-x shell-command RET. At the prompt, I manually enter pandoc -s myfile.tex -o myfile.org. What command will save me the trouble of having to type out the myfile ...
  • 1,712
1 vote
1 answer
117 views

is it possible to execute a command on specific set of files upon exiting emacs

I use emacs as my editor with mutt. I would like to run a python code on the /tmp/mutt-* files upon exit (that is called email-process, and that is written and works). For instance, in the case of vim,...
0 votes
2 answers
43 views

Pass arguments captured from minibuffer to shell command in a function

I'm struggling with passing arguments read from the minibuffer to a shell command in a elisp function. I've written the following so far: (defun perlclean (review clean) "Script PERL blablabla&...
  • 179
1 vote
0 answers
22 views

Locally shell-process remote files?

I'm using https://github.com/schspa/dtb-mode to transparently decompile binary dtb files; dtb-mode does this by running dtc on the underlying file (which, AFAICT, doesn't accept input from stdin). ...
0 votes
0 answers
41 views

start-process permissions in Windows

I can open an HTML file using shell command: M-! start file.html, but when I try to write an elisp function which includes the line (some of these arguments are actually variables but I've written out ...
  • 1,004
0 votes
2 answers
107 views

Elisp function to open file name with space?

To open a file with default associated application, I have this function, which works as I expect, except with a file name that has space: (defun open-a-file () (interactive) (let (...
  • 1
0 votes
1 answer
318 views

how to execute shell command with piping in Elisp?

I am trying to duplicate the following bash command in Elisp: curl https://google.com | readability https://google.com Here's what I have so far, but it doesn't capture the piping "| readability&...
0 votes
1 answer
36 views

From an org item, launch a shell command with the item text as parameter

From an org list item, I want a function that I can bind to a shortkey or an org-speed shortcut, to be able to launch a shell command with the org list item text as parameter. Then I want to add tag ...
  • 103
0 votes
2 answers
179 views

Pass selected text as argument to a script and replace selected text with output from the script

I'd like to pass some selected text in a buffer to a python script. The python script will process the string and print the result to stdout. This output should replace the original string that was ...
  • 169
0 votes
1 answer
227 views

Pseudo-terminal will not be allocated because stdin is not a terminal. ssh_askpass: exec(/usr/libexec/openssh/ssh-askpass): No such file or directory

CentOS 7, Emacs 27.1 Here content of file myFile.sh: ssh myuser@10.111.11.111 So when in vterm mode I use this: ./myFile.sh then I success connect to the remote machine (ip = 10.111.11.111) by ...
  • 3,495
1 vote
1 answer
50 views

How to run commands locally even when on tramp?

I have some commands that do "utility" stuff that have nothing to do with the current buffer. I need these to always run locally, and not remotely when visiting a tramp buffer. How can I do ...
  • 630
1 vote
1 answer
48 views

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

I am on Ubuntu. I'm trying to run the latex command to run in the Emacs shell. I have done some research, and have already done the following: I noticed that running env in the Emacs shell gave a ...
2 votes
1 answer
179 views

How can I automatically rename buffers created with `async-shell-command` to the shell command that was called?

I am often opening exwm buffers by running async-shell-command but unfortunately these buffers always get named *EXWM*. It would be great if when I ran async-shell-command 'firefox the buffer that ...
2 votes
1 answer
480 views

Print shell-command output to STDOUT?

Is there an equivalent of C's system(char*) or Python's os.system(string) for emacs --script? I want to use Emacs for shell-scripting purposes. However, I cannot find a function that allows running an ...
  • 1,501
1 vote
1 answer
145 views

How to call Elisp functions from my own implementation of a shell?

I'm writing my own shell which can handle most of the GNU/Linux system calls now. So I was wondering if I could make this shell call Elisp functions too. Is it possible to do so? Is so, how do I get ...
0 votes
1 answer
112 views

Open current file in Vim

I've got this from EmacsWiki: (defun my/open-current-file-in-vim () (interactive) (async-shell-command (format "gvim +%d %s" (+ (if (bolp) 1 0) (count-lines 1 (point))) ...
2 votes
0 answers
29 views

Exec a external shell command that have external read input - ex:cookiecutter

As the examble like cookicutter, it have a read input in itself that we must type if we use it in normal terminal. $> #comment: this is normal terminal emulator $> cookiecutter $HOME/...
  • 31
0 votes
1 answer
130 views

Prompt for stdin via `shell-command`

Sometimes when I copy+paste into my spacemacs over SSH, I get some random garbage that seems to be due to spacemacs interpreting some of the pasted content as commands. In vim, my workaround is to run ...
0 votes
1 answer
182 views

Cannot paste text copied from Emacs to synchronous subprocess

TL;DR When trying to paste text copied/killed in Emacs to another program while Emacs is waiting for a synchronous subprocess to finish, the target program hangs until Emacs becomes responsive again. ...
  • 1,501
0 votes
1 answer
81 views

Display Δ in the *Shell Command Output* Buffer

I have a shell command I'm running from Emacs that has a Δ character in its output. How can I configure the *Shell Command Output* buffer to display UTF-8 by default? edit: There could also be ...
  • 165
0 votes
0 answers
285 views

Execute a command from a buffer

Say, you create a new buffer (Fundamental), type a shell command and want it executed. Like you can do in a *scratch* buffer with lisp code (C-x C-e). Or you have a text file, that has text ...
  • 259
0 votes
1 answer
158 views

Insert string output of shell-command in current buffer

The code below calls upon a Python script to generate pinyin from Chinese characters in region: (defun pinyin () "Generate Pinyin from Chinese Characters with Python script, keeping the original ...
  • 655
0 votes
0 answers
19 views

reference mutltiple selections or registers for shell-command-on-region

C-u M-| is wonderful for things like running sort a region. But I've wandered into an interesting place. I wan to run join or comm on two regions in a buffer. # region 1 a 1 b 2 z 26 # region 2 a ...
  • 203
2 votes
2 answers
774 views

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

I want to use async-shell-command to run a .bat file on Windows. Reading the function documentation it says: (defun async-shell-command (command &optional output-buffer error-buffer) "Execute ...
  • 2,099
1 vote
1 answer
513 views

Emacs shell not picking aliases from bashrc

NOT Working: /bin/bash: Psu: command not found M-! cmd Psu Working M-! cmd ls .bashrc cat ~/.bashrc | grep Psu cat ~/.bashrc | grep aliases alias Psu='sudo pacman -Syyu' if [ -f ~/.bash_aliases ]; ...
  • 629
0 votes
1 answer
463 views

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

Given lines like these: pwd echo "Hello \ World" in a buffer, I would like to do the following: Put the cursor to the first line, then press C-` Select lines 3-4 then press C-` to send the line ...
  • 115
0 votes
2 answers
50 views

Creating Shell-Based Filter in .emacs.d/init.el

This could be a useful FAQ for non-emacs-programmers. What should I put into .emacs.d/init.el in order to hard-code a specific shell filter that will replace the contents of the region? For ...
  • 113
1 vote
2 answers
717 views

Compile and run single file c++ programs in Emacs[SOLVED]

I want to bind to a key a compile-and-run function to be able to compile my C++ single file programs and run them into a term/shell so I could give my variables values whenever I use cin in my ...
0 votes
2 answers
496 views

How can I do a regex search recursively from a directory?

Basically I want a command that can do the following: find /path/dir -type f -print0 | xargs -0 grep -l "foo" Is there an emacs command to do this? If not, then is there a convenient keybinding that ...
0 votes
1 answer
359 views

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

I am having some trouble understanding how shell-command-on-region works. Sometimes the region is passed to command, sometimes not, as far as I can tell. Suppose I have an emacs buffer with "word" in ...
  • 155
1 vote
0 answers
43 views

Allow user to interact with subprocess

I would like to call a subprocess, and that subprocess has some interactive behavior. Thus, I would emacs to parse the output of the subprocess, ask the user for input, and then hand that input back ...
0 votes
1 answer
344 views

send custom commands to shell

I have just joined the Emacs church. I would like to know if the following can be done. Say I have a project folder, I would like to run some custom commands that tie to some keyboard shorcuts for ...
  • 295
1 vote
0 answers
97 views

In emacs term-mode (not shell-mode), how can we edit a command just like we type C-x C-e in real terminal

In real terminal, if we type C-x C-e, we can edit a typed command using an editor. Could have similar function in emacs term-mode? After typing a shortcut, I would like to edit the current command ...
  • 1,001
0 votes
1 answer
381 views

Emacs / Projectile complains about no job control with Bash/terminal

I use Emacs 27.0.50 on Ubuntu 18.04. Fish is my default shell. When a file from a directory with .git is being loaded into the buffer, I'm trying to start projectile-find-file , I see the following ...
  • 3,765
5 votes
2 answers
139 views

How to pipe large files through fold before opening?

On a regular basis I need to open files that have really long lines, which unfortunately causes emacs to grind to a halt. My understanding is that this is a long-term issue with the renderer. I've ...
1 vote
2 answers
478 views

Multi-processing via TRAMP with asynchronous shell commands

I found the following code in TRAMP: (defun tramp-adb-handle-shell-command (command &optional output-buffer error-buffer) "Like `shell-command' for Tramp files." (let* ((asynchronous (...
5 votes
1 answer
222 views

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

I am transitioning to Emacs with evil-mode after years of Vim. For work reasons I have to use a GUI statistics program (Stata) frequently. This program does not integrate well with external editors. ...
1 vote
1 answer
366 views

How to make *Shell Command Output* buffer scroll to the end?

I often execute shell commands via M-! and their output is then shown in the buffer *Shell Command Output*. How can I make this buffer display the end (rather than the beginning) so that I can see ...
1 vote
2 answers
272 views

Inhibiting `finished:` message from `async-shell-command`

Running (async-shell-command "echo test") prints echo test: finished to the echo area upon completion. I am running a function in the background on a loop with a special handler, and the message is ...
1 vote
2 answers
63 views

How can I get the list of recentf files from bash / cli?

How can I retrieve the list of recent files in bash? I'd like to get this set of files so I can use it with rofi. I could manually parse the data file that looks something like: ;;; Automatically ...
5 votes
1 answer
888 views

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

I'm running this emacs GNU Emacs 25.2.2 (x86_64-pc-linux-gnu) of 2017-09-22, modified by Debian directly in a Gnome terminal by calling emacs, which is actually a link to /etc/alternatives/emacs. ...