This is done via a process filter.
By default comint-output-filter-functions includes comint-watch-for-password-prompt, which is the filter function that handles this.
If it sees text matching comint-password-prompt-regexp then it calls send-invisible to prompt the user for a password.
For more information about how process filters work, refer to C-hig (...
glucas is exactly correct, but to supplement his answer I have this piece of code I've used myself to make here doc insertion a little smarter.
This advice, coupled with sh-electric-here-document-mode enabled, make it so that if you type two chevrons the automatic here doc will be created, but then if the next character you type is another chevron, it will ...
This is caused by sh-electric-here-document-mode. When enabled, << will insert a here document skeleton.
This is enabled by default. You can disable it with a hook, such as:
(add-hook 'sh-mode-hook (lambda () (sh-electric-here-document-mode -1)))
I think the first part of your question can be done with dirtrack-mode. First, you set your shell prompt to include the present working directory. Next, you set dirtrack-list to a regex that tells dirtrack-mode how to extract it. Example: I set PS1 in Bash to be this:
export PS1="[\h:\w] $ "
and in Emacs I set dirtrack-list and turn on dirtrack-mode:
The control sequences ^[[?2004h and ^[[?2004l turn bracketed paste mode on and off.
Shell mode doesn't support bracketed paste mode (with these or any other control sequences), so zsh shouldn't try to turn it on. Shell mode correctly advertises that it doesn't support these control sequences by declaring TERM=dumb. It seems that zsh blindly assumes that the ...
Setting sh-basic-offset to the required indentation is what is needed - but what I didn't realise is, it's also necessary to close and reopen all shell script files before the customisation takes effect. I can't remember ever having to do this before in emacs.
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 ...
My Emacs (GNU Emacs 24.5.1) sets TERM=dumb in startup.el and my ls from GNU coreutils 8.24 checks TERM even with --color=always. dumb is not a terminal type recognized by dircolors (the utility used by ls to decide how to color the output), so running TERM=ansi ls --color=always in a *shell* buffer works as expected, while ls --color=always does not.
So, I ...
I would recommend you to try out company-mode. It has a built-in backend company-capf which fetches completion candidates from emacs' completion-at-point-functions (the same mechanism that powers completion in the shell) as such completion offered by company are as accurate as the built-in shell-mode while making the user interface is very convenient.
Configure comint-password-prompt-regexp so that it includes whatever text pass gives at the second prompt.
Alternative answer, instead of just typing the password, you could type M-x send-invisible RET enter-the-password RET.
I should always have one frame devoted to exactly one of these three windows (on the bottom) and there should be some way to cycle through them.
I recommend using shell-switcher, which keeps a register of shell buffers and allows you to easily switch between them with C-'.
I use eshell as my primary shell and have it configured to work with shell-switcher:
What is determining whether you see shell-script[fish] or shell-script[bash] is probably:
The extension of the file (*.sh files will probably open with shell-script[bash], and *.fish files will probably open with shell-script[fish])
The starting #!-line (e.g., if the first line of the file you are opening is #!/bin/bash, it should start in shell-script[bash]...
Finally found a fix with a bit of a hack with the help of edebug-defun!
The keyword highlighting of shell-script-mode is good. But the problem was that it set the indent-line-function to sh-basic-indent-line when sh-shell was set to tcsh. That function caused the extra indentation by 4 spaces.
There is an outdated csh-mode.el (last updated in 1999) which ...
For the indentation after the | you should be able to get the right result by going to the incorrect line (i.e. the one that starts with grep) and then do M-x smie-config-set-indent RET before "|" RET nil RET.
But smie-config is not up to the task when it comes to tweaking the behavior of the close paren in the way you want. For that you'll need actual ...
shell-mode is used by the interactive shell (command line) environment started by the shell command (spc : shell, or M-x shell in regular Emacs). It is a variant of the comint mode, which sends lines of interactive input to an external ("inferior") program -- like a lisp repl, python shell, ..., or your system shell in this case -- and puts its output back ...
Use Literate DevOps Method
I recommend using the literate devops method via org-mode, that @phils suggested in the comments, because of the ease of use and adaptable workflow.
Create or open an org-mode file to store an manage your notes and annotations. e.g. C-x C-f ex1-annotations.org
Add a new shell SRC code block using built-in easy ...
Not the best solution, but certainly a working one: Use [dirtrack-mode]. The following preparations are needed:
1. On the remote machine:
Make sure the prompt of the remote shell contains the path including the server login in TRAMP notation (e.g. /firstname.lastname@example.org:/home/user). You can achieve this by setting PS1 (e.g. in the .bashrc file on the remote ...
Do it like you would do it in xterm:
If you always want to set the same variables in shell-mode but not xterm then add this to your shells init file:
if test -n "$INSIDE_EMACS"
Or in Emacs
(add-hook 'shell-mode-hook 'my-shell-mode-hook)
(defun my-shell-mode-hook ()
This is a subset of your question, but it should help in that the following code may be extended to serve larger purposes and that I share my investigations.
I asked a similar question on SO about changing directory with ido. Someone answered, which maybe @iqbal-ansari will recognize, and I put the resulting code into a repo which I called fasd-shell. The ...
Instead of select-and-copy manually, you can also write a command and
let it do the work for you:
;; Adapted from `comint-delete-output'
(defun comint-copy-output ()
"Copy all output from interpreter since last input."
(let ((proc (get-buffer-process (current-buffer))))
(let ((pmark (progn (goto-...
By default the binding to do this in Emacs' shell-mode is M-r which runs the command comint-history-isearch-backward-regexp. This allows you to search backwards though your input history using a regular expression.
Personally I prefer the comint-previous-matching-input-from-input command, which is by default bound to C-c M-r. I have it bound to the ...
Consider using term-mode rather than shell-mode. In term-mode you can switch between "character mode" (where commands like C-r go directly to the terminal) and "line mode" (where commands are first interpreted by Emacs). C-c C-j activates line mode and C-c C-k character mode. Character mode gives C-r the behavior you want while line mode makes the ...
Chances are that you'll want to do this for numerous modes, so I would suggest using an approach which makes that simpler to specify. e.g.:
(defun my-hide-trailing-whitespace-maybe ()
"Disable `show-trailing-whitespace' in selected modes."
(when (derived-mode-p 'shell-mode
As commented, watch needs to run in a terminal so that it can do all the fancy things that it does. In Emacs, that means running it via term.
The very simplest thing is to invoke it from a shell running in M-x term
You can also run the watch process directly in the terminal, but because the command needs arguments, doing that requires a custom wrapper ...
An alternative solution:
(add-to-list 'eshell-visual-commands "watch"))
To run command like watch -d date, issue:
M-x eshell-command RET watch -d date RET
The watch command requires a terminal emulator, which usually needs control keyboard events by itself, thus most Emacs key bindings will not work. Emacs provides a ...
You can clear the shell buffer like any other, if you get the cursor away from the current prompt, where its movement behavior is different. Here's one recipe, which feels intuitive to me but looks long when I write it down.
<Enter> to get a fresh prompt
C-b C-a moves the cursor to the beginning of the current line, to the left of your prompt
eshell-postoutput-scroll-to-bottom in the hook eshell-output-filter-functions is causing to scroll to bottom and so to remove it from the hook add this snippet to emacs config
(defun rm-eshell-postoutput-scroll-to-bottom ()