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
1answer
20 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
0answers
15 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/...
0
votes
1answer
36 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
1answer
28 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. ...
0
votes
1answer
36 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 ...
0
votes
0answers
52 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 ...
0
votes
1answer
28 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 ...
0
votes
0answers
17 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 ...
0
votes
2answers
57 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 ...
0
votes
1answer
67 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 ...
0
votes
1answer
119 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 ...
0
votes
2answers
39 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 ...
1
vote
2answers
198 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
2answers
49 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
1answer
75 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 ...
1
vote
0answers
33 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
1answer
119 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 ...
1
vote
0answers
45 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 ...
0
votes
1answer
167 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 ...
5
votes
2answers
88 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
2answers
222 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
1answer
118 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
1answer
163 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
2answers
124 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
2answers
59 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 ...
3
votes
1answer
529 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. ...
0
votes
2answers
445 views

Multiple async-shell-command commands in sequence

What is the correct way to run multiple async-shell-command invocations serially? For example, this will execute all at once. (progn (async-shell-command "echo 1; sleep 1") (async-shell-command ...
1
vote
1answer
99 views

Sudo caching on compilation mode

There is a command I run very often using compile that must be run as sudo. I wanted to achieve something similar to the 5min caching of sudo in a shell: if I keep running the command in intervals ...
1
vote
2answers
219 views

Split command line into a list of arguments

How do I take a string giving a shell command line such as: "program arg1 arg2 \"long argument with spaces\" arg\\\"3" and turn it into a list of unquoted arguments like: ("program" "arg1" "arg2" "...
1
vote
1answer
178 views

Run custom bash functions with M-!

I have a few custom bash functions that are defined is some file and are made available to me in regular terminals via the line . "/path/Custom Bash Functions.sh" in my ~/.bashrc. However, Emacs ...
0
votes
1answer
94 views

Change async-shell-command with a synchronous command keeping the dynamically displayed buffer

I have this snippet of code: (async-shell-command (concat "perl myscript.pl " (buffer-name)) (read-string "RETURN: ") (with-temp-file "file.new" (insert-file-contents "file.new") (perform-...
0
votes
2answers
243 views

shell command on region with process substitution

If I want to execute a shell command on a region I know I can use shell-command-on-region via M-|, what if the command I want to redirect my selection does not accept redirection to it's standard ...
2
votes
1answer
192 views

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

I'm customizing spacemacs for my workflow. I'm new to elisp and can't figure out how to do this after looking at other functions in .el files and other posts. Basically, I wrote an elisp function ...
5
votes
1answer
1k views

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?
5
votes
1answer
704 views

Differences between cmdproxy.exe and cmd.exe

What is the difference between: (call-process "cmdproxy" nil "foo" nil "/c" "dir") (call-process "cmd" nil "foo" nil "/c" "dir") ? I seem to get exactly the same results in Emacs 25.1 on ...
1
vote
1answer
200 views

Calling shell-command from org-capture-templates to scrape verb conjugations

I want to use org-capture-templates to scrape french verb conjugations from the web and insert them into an org-file to use with org-drill. I have a (functioning) scraper that gets the desired data ...
0
votes
1answer
985 views

Saving to clipboard in a Python script running as shell command

The following python script successfully copies a given string into the clipboard when run from Ubuntu shell: import os text = 'The text to be copied to the clipboard.' os.system("echo -n {s} | xsel -...
9
votes
2answers
211 views

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: ...
5
votes
1answer
246 views

Asynchronous version of shell-command-on-region?

I have a problem which is very similar to this one. I have some text that I'd like to listen to with macOS's say utility. Unfortunately, Emacs locks up when I use shell-command-on-region because it is ...
8
votes
2answers
563 views

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 ...
1
vote
1answer
69 views

is there a shell-command-at-point

This is a bit of a long shot, but I'm going to ask anyway. Kinda similar to what dired-at-point and find-file-at-point When point is inside a .txt file on a line like this ls -la /tmp/ When point ...
1
vote
1answer
140 views

How to improve the `M-! command` output

I found this really cool in emacs M-! t t is ~/bin/t, and runs tests for whatever thing I'm working on. I added ~/bin/ to my /etc/path.d/, and I always use emacs -nw. My issue is, the command ...
0
votes
1answer
97 views

Best way to test output sent to a buffer

I'm writing an emacs package for Pipenv and the spike solution uses sync shell calls, which is not desirable for general usage. I'm now changing calls to be async (make-process) and for output to go ...
1
vote
1answer
367 views

Git bash opens in window outside of emacs

When running Emacs on Windows 10, I am able to launch git bash from within Emacs using the information given here, here, or here. For example, I can just add these two lines to my .emacs: (setq ...
4
votes
1answer
214 views

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

I'd like to replace my selection with the output of a program, an annoyance is - when there is an error, the error replaces my text. Is there a way to check the exit code and only replace the text if ...
1
vote
2answers
225 views

How to evaluate the selection through Python and replace the selection with it's result?

Being more familiar with Python then elisp, I'd like to evaluate the selection as as Python snipped - as a short-cut to opening a calculator or Python prompt and copy-pasting between them. Is there a ...
0
votes
1answer
111 views

How to paste to another app from a shell script

I've been getting very vexed by the following. Goal: Take the clipboard contents and paste them into another application by using a shell script called by Emacs, followed by a Return. [This is for ...
4
votes
2answers
915 views

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 ...
1
vote
0answers
95 views

Problem execution scope org-babel in shell on windows 8

I just discovered that in order to run a sequence of shell commands under the same scope (same shell session) I have to add a hash at the end of the line. Example When I try to run the following ...
4
votes
1answer
208 views

Refresh `async-shell-command` buffer

When I run a command with async-shell-command, sometimes I would like to quickly rerun the command. I can do this by running async-shell-command again and using M-p to cycle backward through history, ...