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.

shell-command is an Emacs command that executes a single shell command in a shell. It puts short output in the and long output in buffer *Shell Command Output*.

Tags related to include , , and .

Useful Links:

137 questions
16
votes
3 answers

Persistent shell-command history

When I run shell-command in a new session I do not have access to the history of commands from the last session. How can I have that?
RasmusWL
  • 267
  • 2
  • 7
16
votes
2 answers

"cannot set terminal process group" error when running bash script

I have the following two lines of code in my init.el file: (setq shell-file-name "bash") (setq shell-command-switch "-ic") I tried executing the following script to get a list of executables using the shell script dmenu_path. (defun dmenu-path-out…
wdkrnls
  • 3,657
  • 2
  • 27
  • 46
15
votes
1 answer

Execute external script upon save when in a certain mode?

When I'm in org-mode, I want Emacs to execute a bash script I wrote whenever I hit C-x s to save. The script automatically syncs the file I am saving to my Raspberry Pi. It expects the file name as argument. How do I tell Emacs to run the external…
qacwnfq q
  • 253
  • 3
  • 6
12
votes
4 answers

Get output of external command in the buffer

How do I get the output of (shell-command "df") (or some other more complex command, that I don't want to retype often) in the current buffer? I run it by typing C-c p after it, but then it opens another buffer and sends the output there.
Yiang Xin
  • 129
  • 1
  • 3
10
votes
2 answers

xclip hangs shell-command

I like to use the xclip utility to capture the output of commands on the clipboard. However, when I try to use it with shell-command it seems to hang. In a "normal" shell I can run a command such as echo "hello world" | xclip -selection clipboard…
shay
  • 203
  • 1
  • 7
10
votes
2 answers

Run ssh-add from Emacs and enter a passphrase

I want to call the ssh-add shell command. So I invoke M-x shell-command RET, and in the minibuffer, I type: ssh-add .ssh/id_rsa The only thing I get is: ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory^M How can I make Emacs give…
Nsukami _
  • 6,341
  • 2
  • 22
  • 35
9
votes
2 answers

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

In Emacs shell, is there a command similar to M-p but which would skip repeated commands? That is, it would go to the next different command. Similar to regular Linux terminal. So if I were to run: ls ./script ./script ./script make and press M-p…
Anton
  • 163
  • 9
8
votes
1 answer

How do i change the default shell for shell-command

I am having an issue with one of the plugins i am running because its trying to use fish and does not like the parameters. Is there a way i can change emacs to use bash for any plugins that use shell-command or similar functions. (setenv "SHELL"…
Oly
  • 583
  • 1
  • 5
  • 15
8
votes
2 answers

Applying a timeout on call-process/shell-command?

In some cases, when delegating work to an external process, it's useful to set a timeout on the command to prevent Emacs from hanging indefinitely. Unfortunately, the following does not work. (with-timeout (1 nil) (call-process "/usr/bin/bash" nil…
Malabarba
  • 22,878
  • 6
  • 78
  • 163
7
votes
1 answer

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

I want to run some Elisp when my command executed by async-shell-command terminates. How can I do this? Does it have completion hooks?
Matthew Piziak
  • 5,958
  • 3
  • 29
  • 77
7
votes
1 answer

How can I add default shell commands for various file types?

When I use ! on a *.tar.bz2 file in Dired, I'm presented with the following prompt: ! on WANem_3.0_Beta2.tar.bz2: {3 guesses} [bunzip2 -c * | tar xvf -] -!- How can I add similar functionality for other file types?
Sean Allred
  • 6,861
  • 16
  • 85
7
votes
1 answer

Run elisp from command line in running emacs

How can I execute elisp in the currently running emacs from the command line? The following command echoes 'hi' but doesn't set 'abc in the emacs instance. emacsclient --no-wait --eval '(message "hi") (setq abc)' Is there a way to modify emacs from…
Joe
  • 1,312
  • 1
  • 8
  • 19
7
votes
1 answer

Key binding with an argument

Say I have a shell command foo that I want to bind to a key. I could do for example: (global-set-key (kbd "C-c f") (lambda () (interactive) (shell-command "foo"))) I would like to be able to pass an argument to foo. An argument will be the name of…
6
votes
2 answers

Using `emacsclient` as `git config core.editor` and invoking `git commit` as `shell-command` in Emacs?

I am trying to use Emacs 25.1.1 (graphical version, Windows 10) as both the primary editor and the editor for git operations. In my workflow, I invoke git through M-x shell-command. I tried the following two options so far: git config --global…
kdb
  • 1,561
  • 12
  • 21
6
votes
1 answer

Why Emacs overrides my PATH when it runs bash?

Why do (shell-command-to-string "echo $PATH") and echo $PATH in eshell differ from echo $PATH from ansi-term and gnome terminal in Ubuntu? Some paths are missing from (shell-command-to-string "echo $PATH") and echo $PATH in eshell. Emacs apparently…
foki
  • 886
  • 8
  • 22
1
2 3
9 10