22 votes
Accepted

How does emacs `shell-mode` know to prompt for sudo?

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 ...
user avatar
  • 43.5k
16 votes
Accepted

How to prevent backspace from deleting my shell prompt?

I think you're looking for comint-prompt-read-only. E.g. (setq comint-prompt-read-only t) should take care of it.
user avatar
  • 25.3k
16 votes

Why does typing '<<<' instead produce '<<EOF\n<' when in shell-script mode?

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-...
user avatar
13 votes
Accepted

Why does typing '<<<' instead produce '<<EOF\n<' when in shell-script mode?

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-...
user avatar
  • 19.2k
12 votes
Accepted

Automatically update default-directory when PWD changes in shell-mode and term-mode

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 ...
user avatar
10 votes
Accepted

Set indentation for shell script function

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 ...
user avatar
9 votes
Accepted

Keymap that is dependent on the buffer

You set shell-command as global key-binding for F1 and you add a hook function to shell-mode-hook that sets the local key binding to mode-line-other-buffer. (global-set-key (kbd "<f1>")...
user avatar
  • 30.3k
8 votes
Accepted

weird characters in shell mode with zsh

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 ...
user avatar
7 votes
Accepted

differences of shell-mode vs. shell-script-mode?

shell-mode is to run shell inside Emacs, shell-script-mode is a major mode for shell script editing. See: https://www.emacswiki.org/emacs/ShellMode https://www.emacswiki.org/emacs/ShMode
user avatar
  • 1,719
7 votes
Accepted

/bin/ls --color=always fails to produce colorized output in shell-mode

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 ...
user avatar
  • 8,952
7 votes

Equivalent of pausing (CTRL-Z bindkey) in shell-mode

C-cC-z, which runs comint-stop-subjob, is the shell-mode equivalent. Use C-hm from your shell buffer to see other bindings on that prefix which may be of interest.
user avatar
  • 43.5k
7 votes
Accepted

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

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 ...
user avatar
  • 4,612
5 votes

Shell bash completion window

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 ...
user avatar
  • 7,298
5 votes
Accepted

inserting passwords into pass from shell-mode

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 ...
user avatar
  • 1,746
5 votes
Accepted

What's a good workflow for having a few dedicated shell sessions?

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 ...
user avatar
  • 5,216
5 votes
Accepted

EMACS shell mode that supports annotations

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. Example Workflow ...
user avatar
  • 4,224
4 votes
Accepted

setenv in shell-mode

Do it like you would do it in xterm: export VARIABLE=VALUE 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"...
user avatar
  • 24.3k
4 votes
Accepted

Fixing forced indentation in shell-script-mode for tcsh

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-...
user avatar
  • 24.3k
4 votes
Accepted

sh-script alignment issues

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 ...
user avatar
  • 25.3k
4 votes
Accepted

How can I change which shell script mode I'm in?

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 ...
user avatar
  • 4,535
4 votes

Set indentation for shell script function

I set-basic-offset to 2 but that didn't seem to work, I went back pressed C-h v sh-<TAB> and realized that there was a sh-indentation I set that variable to 2 and everything seems to work like a ...
user avatar
4 votes

differences of shell-mode vs. shell-script-mode?

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 ...
user avatar
4 votes
Accepted

How to send *shell* stdout directly to kill-ring?

Emacs Command 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 ...
user avatar
  • 13.6k
4 votes
Accepted

how to watch and cat and grep with emacs

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 ...
user avatar
  • 43.5k
4 votes

how to watch and cat and grep with emacs

An alternative solution: (with-eval-after-load 'em-term (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 ...
user avatar
  • 13.6k
3 votes
Accepted

Directory tracking in remote shell buffer

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 ...
user avatar
  • 1,041
3 votes

Shell bash completion window

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 ...
user avatar
  • 1,041
3 votes

Get the same/map bindkeys in shell mode, in particular CTRL-r

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 ...
user avatar
  • 707
3 votes

Get the same/map bindkeys in shell mode, in particular CTRL-r

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 ...
user avatar
  • 12.1k
3 votes
Accepted

Symbol's value as variable is void: shell-mode-map

Drew is right you need to load the package, which defines shell-mode-map (require 'shell) ;; your code based on functions and variables defined in shell.el Explanation At the end of your Emacs's ...
user avatar
  • 878

Only top scored, non community-wiki answers of a minimum length are eligible