Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
0 answers
51 views

Add a shell command to dired mode

I want to add a command to dired-mode, which executes a shell command on the highlighted file. For example, from Bash, I can run qvm-copy {FILENAME}. I would like to replicate this behavior, but from ...
ch-pub's user avatar
  • 220
0 votes
1 answer
33 views

How to insert fontified git diff output into Emacs buffer?

I wrote this code: (defun compare-string-test (String1 String2) (interactive) (let ((Temp1 (make-temp-file "gitdiff" nil nil String1)) (Temp2 (make-temp-file "gitdiff" ...
Gabriele's user avatar
  • 1,618
0 votes
1 answer
64 views

"Aliasing" `ls` to `gls`

gls not ls: My system has two forms of ls, the standard "old school" version of ls, and GNU ls which is available as gls. In my shell, I simply created an alias to use gls, but I have not ...
Anoduck's user avatar
2 votes
1 answer
73 views

Difficulty inserting current weather with org-roam dailies template

I am trying to get the current weather inserted into my org roam dailies. Here is the default capture template I'm starting with, from https://systemcrafters.net/build-a-second-brain-in-emacs/keep-a-...
Edward Doolittle's user avatar
0 votes
1 answer
28 views

pass arguments in call-process as key/value

I try to run a command which takes some arguments and requires to pass some attributes to the API. I understand that call-process takes args as strings but any invocation complains about wrong-type-...
b10n1k's user avatar
  • 101
1 vote
1 answer
124 views

Dired shell command with parameters

I want to provide additional command line options to a command in dired marked with '!', eg how do I add '-V' to something like 'less'?
balanga's user avatar
  • 135
0 votes
0 answers
85 views

Executing commands from a buffer

Following instructions here:- https://www.emacswiki.org/emacs/ExecuteExternalCommand which says: Using the whole buffer If you are programming using an interpreted language, such as Perl or Python, ...
balanga's user avatar
  • 135
0 votes
2 answers
65 views

shell-command-on-region doesn't execute an executable script named in exec-path

I am on MacOS (12.6.1, Monterey) running Emacs 29.1 (installed from https://emacsformacosx.com). I have a set of shell scripts that I have often use with shell-command-on-region (M-|); the scripts are ...
cforster's user avatar
  • 101
0 votes
0 answers
32 views

How can I enable shell-command in Termux build of Emacs?

Installation of emacs on termux (from f-droid) does not support shell-command. Does this require a port of shell access code to termux, or is it some sort of option that I would be able to activate?
jim theriot's user avatar
1 vote
1 answer
52 views

Getting dired to open an xterm instance without waiting

I like to use dired-do-shell-command to open audio and video files in an independent terminal using the default command gnome-terminal -- mplayer * and this works great. But now I've changed my ...
Alexander Praehauser's user avatar
0 votes
0 answers
17 views

Why doesn't Imagemagick's import utility work when called from async-shell-command, but works as expected when called from vterm?

I'm trying to get screenshots working in EXWM. From vterm if I issue the command import png:- | xclip -selection clipboard -t image/png this turns my mouse cursor into a crosshair, prompting me for a ...
Dargscisyhp's user avatar
0 votes
1 answer
46 views

In elisp, how can I convert a string to an escaped string?

In DirEd, when I copy a filename, using C-u 0 w , it's copied fine, but I can't use this string in a shell command, cause it's not escaped. Is there a function to convert a string to an escaped ...
Jason Hunter's user avatar
0 votes
0 answers
68 views

`shell-command` repeats my input characters multiple times

whenever I run this command (shell-command "chatgpt install &") my input characters gets repeated like this: 1> hi hi Hello! How can I assist you today? 2> hi again hhii ...
ntriisii's user avatar
0 votes
0 answers
38 views

Best way to get man to open in emacs by default

I currently have: man () { emacs -nw --eval "(man \"$1\")"; } in my .zshrc. However, this has the problem of not working with something like read(2) or command-line arguments to ...
user129393192's user avatar
0 votes
2 answers
108 views

Why does shell command insert a newline in the output buffer?

I have this code: (with-output-to-temp-buffer OUTPUT_BUFFER (shell-command (format "unzip -p %s %s | cat" ZIP_FILE_NAME LOG_FILE_NAME) OUTPUT_BUFFER OUTPUT_BUFFER)) I read a .log ...
Gabriele's user avatar
  • 1,618
0 votes
1 answer
51 views

Why is my simple use of shell-command to change a global keybinding in Linux not working?

I want to be able to change a global keybinding by calling an Emacs function. The command in question is: gsettings set org.gnome.desktop.wm.keybindings switch-applications "['<Super>Tab']&...
Orixi's user avatar
  • 5
0 votes
1 answer
99 views

How can I disable helm file completion for interactive shell command?

I have turned on (helm-mode 1) and selectively turned it off for find-file for default emacs behavior, which I prefer. I would also like to restore non-helm behavior for file completion when invoking ...
Dov Grobgeld's user avatar
2 votes
4 answers
469 views

Running and viewing results from bash scripts

How can I run bash scripts from emacs and show the result in emacs?
Dilna's user avatar
  • 1
1 vote
1 answer
1k views

How to run yarn in a bash script from emacs?

I have a bash script like this: #!/bin/bash cd ~/src/program && rm -rf node_modules && yarn When I invoke this script by executing (shell-command "bash ~/src/helper/script.sh&...
Evgeny Mikhaylov's user avatar
0 votes
3 answers
238 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 ...
equator's user avatar
1 vote
1 answer
170 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,...
Seki's user avatar
  • 157
3 votes
1 answer
242 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 ...
Ananth Pattabiraman's user avatar
0 votes
1 answer
104 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 ...
Duncan W's user avatar
  • 113
1 vote
0 answers
39 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 ...
rahmu's user avatar
  • 111
0 votes
1 answer
30 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 ...
Hercislife's user avatar
0 votes
1 answer
107 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 --...
Schach21's user avatar
1 vote
1 answer
89 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. ...
Peter Slotko's user avatar
0 votes
1 answer
139 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 ...
stand's user avatar
  • 115
3 votes
3 answers
117 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 ...
deshmukh's user avatar
  • 1,912
1 vote
1 answer
351 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,...
user3236841's user avatar
0 votes
2 answers
179 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&...
Guillaume's user avatar
  • 189
1 vote
0 answers
25 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). ...
Sebastian Sturm's user avatar
0 votes
0 answers
72 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 ...
hatmatrix's user avatar
  • 1,096
0 votes
2 answers
308 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 (...
Sahara's user avatar
  • 1
0 votes
1 answer
868 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&...
Webdev Tory's user avatar
0 votes
1 answer
43 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 ...
taharqa's user avatar
  • 103
0 votes
2 answers
629 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 ...
linuxfan's user avatar
  • 209
0 votes
1 answer
751 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 [email protected] So when in vterm mode I use this: ./myFile.sh then I success connect to the remote machine (ip = 10.111.11.111) by ...
a_subscriber's user avatar
  • 4,124
1 vote
1 answer
128 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 ...
HappyFace's user avatar
  • 830
2 votes
1 answer
272 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 ...
Russ Phelan's user avatar
2 votes
1 answer
325 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 ...
Nicholas Hubbard's user avatar
2 votes
1 answer
842 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 ...
kdb's user avatar
  • 1,561
1 vote
1 answer
208 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 ...
Veera Sivarajan's user avatar
0 votes
1 answer
163 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))) ...
Arktik's user avatar
  • 972
2 votes
0 answers
35 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/...
Kidman's user avatar
  • 31
0 votes
1 answer
217 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 ...
Patrick Collins's user avatar
0 votes
1 answer
447 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. ...
kdb's user avatar
  • 1,561
0 votes
1 answer
101 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 ...
Aido's user avatar
  • 175
0 votes
0 answers
446 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 ...
x-yuri's user avatar
  • 291
0 votes
1 answer
216 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 ...
Sati's user avatar
  • 815