22

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 (...


17

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 ...


15

I think you're looking for comint-prompt-read-only. E.g. (setq comint-prompt-read-only t) should take care of it.


13

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)))


12

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: (...


7

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'. Documentation: If non-nil, don't add input matching the last on the input ring. This mirrors the optional behavior ...


6

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 ...


6

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


6

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.


5

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.


5

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 ...


5

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. You ...


5

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: ...


4

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.


4

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 ...


4

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 ...


4

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]...


4

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 ...


4

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 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 ...


3

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. /user@myserver.com:/home/user). You can achieve this by setting PS1 (e.g. in the .bashrc file on the remote ...


3

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" then export VARIABLE=VALUE fi Or in Emacs (add-hook 'shell-mode-hook 'my-shell-mode-hook) (defun my-shell-mode-hook () (process-send-string (get-...


3

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 ...


3

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 from interpreter since last input." (interactive) (let ((proc (get-buffer-process (current-buffer)))) (save-excursion (let ((pmark (progn (goto-...


3

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 M-< ...


3

You can test the TERM environment variable in your bashrc file. For M-x shell it will be "dumb" as opposed to anything else. For ansi-term the TERM environment variable is set to "eterm-color".


2

By default, emacs 24.4 turns on electric-indent-mode which makes it indent automatically. Disable it and you won't have that problem anymore: (add-hook 'after-change-major-mode-hook (lambda() (electric-indent-mode -1))) I set newline-and-indent to RET globally and have no problem: (global-set-key (kbd "RET") 'newline-and-indent)


2

The shell-dirtrack-mode is an alias to shell-dirtrackp. The shell-dirtrackp is initialized with the value of t in shell.el. So this variable and thus the minor mode shell-dirtrack-mode gets a global value of t. So this mode state is always on in a fresh buffer unless you actively disable it. The solution is to change the default value of the shell-...


2

Setting comint-input-ring-separator so that the whole timestamp is treated as part of the command separator worked for me. For example: ; Remember lots of previous commands in shell-mode (setq comint-input-ring-size 100000) (add-hook 'shell-mode-hook 'my-shell-mode-hook) (defun my-shell-mode-hook () (setq comint-input-ring-file-name "~/.zsh_history") ; ...


2

You want to look at sh-syntax-propertize-function where it currently uses the regexp "\\(?:[^|&;<>()``\\\"' \t\n]\\|\\${\\)\\(#+\\)" to match those # chars which should not be considered as starting a comment. If you remove the ( char in the char range (i.e. replace () with just )), then it should solve your particular problem. It will also cause ...


2

You can explicitly set which shell M-xshell uses by customizing explicit-shell-file-name If your zsh config causes problems with shell you might try M-x term or ansi-term instead which may play better with your config. If nothing quite works right, you could always use tmux or screen to flip between emacs and a real shell.


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