The short answer is enable (savehist-mode) in your .emacs. This will save all minibuffer history rings by default, which includes shell-command-history which is used by M-! / (shell-command).
While I'm at it, I figure I'll also explain how to load/save command histories from shell-mode prompts and other modes that derive from comint-mode.
Note: this is for ...
The -i flag requests that Bash run in interactive mode, which requires a terminal. The solution is to leave the shell-command-switch variable at its default value, which is just -c.
If you really need to run Bash in interactive mode, you will need to run it in a pseudo-terminal, by using start-file-process with process-connection-type bound to t.
Here's a simple setup that you can modify that allows you to sync org files to your Raspberry Pi, based on your bash script (untested, of course, because I have neither a Pi nor your script). Modify the function with your script name. It uses shell-command-to-string to put the command line output somewhere; you could also just use shell-command if that's ...
This functionality comes from dired-x, not Dired. Use (require 'dired-x) in your init file and then customize dired-guess-shell-alist-user.
We can see though where Dired plugs into dired-x:
(defun dired-read-shell-command (prompt arg files)
"Read a dired shell command.
PROMPT should be a format string with one \"%s\" format sequence,
which is ...
Shell commands usually terminate their output with a newline. shell-command-to-string doesn't add a newline, it merely stores the contents of the output of the shell command — including the final newline, if any — in a string. Compare
(shell-command-to-string "echo hello")
which contains the final newline generated by echo, and
You need to change the option shell-file-name.
(setenv "SHELL" "/bin/bash")
This doesn't work since Emacs is already running thus it's too late, Emacs initializes shell-file-name according to SHELL during startup. Something like
$ SHELL=/bin/bash emacs
(setq explicit-shell-file-name "/bin/bash")
This is for M-x shell, not M-x shell-...
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 variable defined in `comint.el'.
If non-nil, don't add input matching the last on the input ring.
This mirrors the optional behavior ...
As Gilles mentioned in the comment above, emacs does not read the local env settings unless specifically asked to. The easiest way to keep variables in shell terminals inside and outside Emacs is to use a package, such as the Steve Purcell's package exec-path-from-shell.
Once installed, this package ensures each time you start a shell in emacs, it reads ...
You can run one-off commands using the magit-run-popup bound to !.
For example, !!ls-files will run git ls-files in the top-level
directory of the repo and output the results to the Magit process
buffer for that repo.
For writing your own commands, you can use one of
Magit's functions for calling Git,
picking the variant depending on the type of Git command ...
Here's one way to put the output of a command into the *Messages* buffer.
(defun my-shell-command-to-message (command)
"Run a command in the shell and append its output to the *Messages* buffer."
(message (shell-command-to-string command)))
Note that it also displays it at the bottom of the screen.
To append the output of a command to a named buffer ...
Given the function
(defun foo (arg1 arg2)
(interactive (list 'interactive-value1 'interactive-value2)
(message "%s %s" arg1 arg2))
You would get
(foo 'value1 'value2) => "value1 value2"
(call-interactively 'foo) => "interactive-value1 interactive-value2"
And when actually using foo as a command
M-x foo RET => "interactive-value1 interactive-...
If you are adding your Haskell bin to your PATH in a .bashrc or similar dotfile, this file only gets loaded when running an "interactive" shell. This happens when running M-x shell but not when running M-! / (shell-command), as there is no prompt. You can adjust the option flags that are sent to (shell-command) by adjusting shell-command-switch to instruct ...
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-process-sentinel; start-process; set-process-filter, etc. and then take the result and plug it in. The following example will return t because the output of git ...
The easy way would be to install ssh-askpass. This is the program that ssh-add runs when its standard input is not a terminal but an X11 display is available. The program ssh-askpass prompts for your passphrase in a separate GUI window.
If you want to stay within Emacs, or if you want a solution that works whether X11 is available or not, you can make Emacs ...
I remember having this problem. It seems that hunspell picks up the language to use for spell-checking from the LANG environmental variable. It appears that the variable is set to 'ENG' in your emacs. What hunspell is saying is that it cannot find dictionaries associated with that language.
You have two options either download the dictionaries that ...
I think I've found the problem and a work-around.
If you look at the python.el file, you will find this function to determine the path to the python executable:
(defun python-shell-parse-command () ;FIXME: why name it "parse"?
"Calculate the string used to execute the inferior Python process."
;; FIXME: process-environment doesn't seem to be used ...
You can achieve this by just adding a GNU timeout invocation to your shell command, which circumvents needing to know any details about Emacs behavior. For example running:
$ timeout 5 sleep 10
Will return in 5 seconds, not 10 (timeout effectively presses Ctrl-C for you).
While call-process is running, emacs will processing events, with-timeout will not work without this:
The timeout is checked whenever Emacs waits for some kind of external
event (such as keyboard input, input from subprocesses, or a certain
time); if the program loops without waiting in any way, the timeout
will not be detected.
You can still use ...
As you seem to have already noticed, a function need the interactive form before it can be bound to a key. interactive doesn't just tell Emacs the function is a command, it is also tells Emacs where to get the functions arguments from. From C-h f interactive:
Specify a way of parsing arguments for interactive use of a function.
For example, write
You can define a variable in the script that records the directory:
You can then use it in your own functions:
(defun my-shell-command (cmd)
(shell-command (expand-file-name cmd my-shell-directory)))
As already explained, the newline is coming from the shell command output.
You can eliminate that by making the shell command format its output with printf (which is portable and reliable when it comes to displaying newlines, unlike echo).
(shell-command-to-string "printf %s \"$(pwd)\"")
Possibly, but there's no need to install a package for this; it's built in.
The command shell-command-on-region (bound to M-| by default) prompts for and then executes a shell command, sending it whatever you have selected on stdin, then displays the output in a temporary buffer. With a prefix arg (so C-u M-|) it replaces the contents of the region with the ...
Actually the shortest way of doing it is to use shell-command with a prefix argument. This is mapped to C-u M-!. The C-u prefix argument changes the standard M-! to insert the output in the current buffer instead of just echoing it in the messages buffer. So, the full command for the df example is
C-u M-! df RET
The command C-u M-| that Emacs User is ...
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, something like:
(define-advice shell-command-on-region (:filter-return (exit-status) failture)
(unless (zerop exit-status)
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'."
(start-process "espeak-process" "espeak-buffer" "espeak" "-v" "en-us")
(process-send-region "espeak-process" (region-beginning) (region-end)))
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 shell and set it with set-process-sentinel.
It is wise to run shell-command-sentinel from your sentinel
since that is the sentinel actually set by async-shell-...
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 caused this function to not work. I am not sure if it makes sense to have the single " in there or not. If it does, you might have to write your own parser.
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-command-on-region).
If the command doesn't support stdin, the following should do what you described
(defun rundo (beg end)
"Wrapper of ~/dotfiles/rundo.sh."...
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
$ fold -w80 myfile | emacs --insert /dev/stdin
This answer was validated using:
emacs version: GNU Emacs 25.2.1
This question was used as a reference.