As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [shell-mode]

is for the major mode for shell buffers. Use `C-c` prefix for accessing `M-x commands`.

Filter by
Sorted by
Tagged with
0 votes
0 answers
32 views

Wrong syntax highlighting with command substitution in sh-mode [bash]

I am using the Doom framework (3.0.0) for Emacs (28.1) on Windows 10 with MinGW64. At least for all practical purposes to the effect of my work, everything seems to be running smoothly except for the ...
Marcos's user avatar
  • 101
0 votes
1 answer
17 views

On tramp shell, commands like `head`, `tail`, `man`, `git log`, etc... output all text at once instead of prompting

I use tramp-shell for ssh to another machine. Setup as follows: (defun spawn-shell (name) "Invoke shell test" (interactive "MName of shell buffer to create: ") (pop-to-buffer ...
Noah's user avatar
  • 121
0 votes
1 answer
46 views

At the time of prompting for a password (from a subordinate shell), sometimes Emacs hides the password, sometimes not. Why the inconsistency?

I use shells running under Emacs (via M-x shell) under a variety of settings1. In all these settings, I use the same .emacs file. Nevertheless I observe an inconsistency, as described below. In some ...
kjo's user avatar
  • 3,105
0 votes
0 answers
17 views

How to make Git Bash and Emacs compatible on Windows?

I have Emacs and Git Bash running on Windows. I know I should not, but sometimes life is grim. I found two problems. The ~ gets expanded differently. In Git Bash ~ means /C/Users/me, but in Emacs ~ ...
ceving's user avatar
  • 1,298
2 votes
1 answer
88 views

Why is navigating in large `*shell*` buffer so slow?

For convenience (at least so far) I am running my program that produces a lot of debug output in Emacs shell. However I have a problem: Sometimes (not all the time) moving the cursor (up, down, left, ...
U. Windl's user avatar
  • 173
0 votes
0 answers
42 views

How to make curly braces auto indent in sh-mode

If typed in sh-mode the closing brace is not auto-indented: function() { } If typed in c-mode the closing brace is auto-indented when inserted: function() { } The exact keystrokes are: f u n c t ...
young_souvlaki's user avatar
0 votes
0 answers
18 views

Is there a way to selectively remove an Emacs shell buffer's shell history entries?

I know how to view a shell buffer's1 shell history, but is there a way to remove entries from this history, so that these entries will no longer be accessible by commands like comint-previous-input? ...
kjo's user avatar
  • 3,105
0 votes
0 answers
53 views

Getting weird completions in shell mode

I'm getting unexpected completion suggestions in shell mode using company. For instance: I have no idea why it's suggesting random DLL filenames here. This is in Linux Emacs built from master of 2022-...
GaryO's user avatar
  • 476
0 votes
1 answer
58 views

shell-mode how to color only keywords

I have following definitions in my .emacs file for keyword coloring in shell-mode: (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) (font-lock-add-keywords 'shell-mode '(("alias " ...
alper's user avatar
  • 1,164
3 votes
1 answer
136 views

Keymap that is dependent on the buffer

I want to create a "toggle shell" shortcut with F1 such that it will run shell when I'm in any other buffer, but will call mode-line-other-buffer when I'm in the shell buffer. What is an ...
Berken Tekin's user avatar
2 votes
0 answers
88 views

shell-resync-dirs hangs

When I run shell-resync-dirs 1, the function hangs, until I press C-g, at which this point, what looks suspiciously like the output of my shell's dirs -l command 2 gets inserted into my buffer at ...
kjo's user avatar
  • 3,105
1 vote
1 answer
46 views

emacs 28.0.50 `sh-quoted-exec` has different coloring for `sh` and `bash`

In Shell-script[bash] mode, coloring differs for sh-quoted-exec in #!/bin/sh and #!/bin/bash. If #!/bin/sh is the first line: // I prefert this If #!/bin/bash is the first line: Would it be possible ...
alper's user avatar
  • 1,164
0 votes
1 answer
356 views

How to make sh-set-shell insert "#!/bin/sh" instead of "#!/usr/bin/sh"

When I open a shell script (e.g. emacs myscript.sh) and do C-c : (M-x sh-set-shell), and select sh as the shell, Emacs will insert a #!/usr/bin/sh shebang instead of #!/bin/sh. I want Emacs to insert #...
Flux's user avatar
  • 583
2 votes
1 answer
42 views

Preventing shell mode from treating ! as a history reference

Various command-line tools, such as gdb, ftp, sftp, etc, use ! to prefix a command to be run in a shell. So (for instance) !mkdir foo will make a directory called foo. When using these tools inside ...
Nick Barnes's user avatar
0 votes
1 answer
429 views

How to send keyboard interrupt to running program in shell mode?

I wish to achieve what a C-c (send a keyboardinterrupt) would do in a terminal outside of Emacs. How do I do that in Emacs shell mode?
topkek's user avatar
  • 79
2 votes
1 answer
115 views

Emacs unable to execute shell commands despite them being in the Emacs shell PATH

I am on Ubuntu. I'm trying to run the latex command to run in the Emacs shell. I have done some research, and have already done the following: I noticed that running env in the Emacs shell gave a ...
Russ Phelan's user avatar
0 votes
1 answer
32 views

shell-mode `alias` keyword is not recognized as font-lock-builtin-face type

In shell-mode; alias keyword is not recognized as font-lock-builtin-face type and remain as white color (with the current theme I am using it should be in different color) => Is it possible to add ...
alper's user avatar
  • 1,164
1 vote
1 answer
56 views

perform shell variable substitution when using find file at point (ffap)

Question: is there a way to convince ffap to perform variable substitution on environment variables before attempting to resolve the file path? I often have lines in shell scripts that read: variable=...
kvantour's user avatar
  • 113
4 votes
1 answer
185 views

How to force filename completion in shell buffers to use quotes instead of backslashes

I have a directory with the file a file name with spaces and in Emacs I have a bash in a shell buffer. Rhen I type ls a<TAB> and shell mode completes to a\ file\ name\ with\ space However I ...
halloleo's user avatar
  • 1,195
0 votes
0 answers
26 views

Dealing with unwanted output

If you used shell-mode for a while, you probably ran into situation where there's a process spitting lots of output very fast, so that C-g and C-c C-c don't really help. One way I found to be somewhat ...
wvxvw's user avatar
  • 11.2k
1 vote
0 answers
199 views

org-babel: zsh sessions use bash

#+BEGIN_SRC zsh :session z1 echo $HOME $0 #+END_SRC #+RESULTS: : /Users/evar /bin/bash I am thinking of trying the workaround outlined here, but shouldn't this work out of the box? Update: I couldn'...
HappyFace's user avatar
  • 738
2 votes
2 answers
438 views

Starting a shell then cd to a specific directory

I want to go to a specific directory after I start a shell. So I put these lines in my .emacs file: (shell) (shell-command "cd C:/MyStartUp/ThisDirectory") (setq default-directory "C:/...
tony's user avatar
  • 113
0 votes
0 answers
19 views

What gets shown in *Messages* when I run pushd in shell, and how to modify it?

I use inferior shells (initiated with M-x shell) extensively. If the current buffer is one such inferior shell, and within this shell I invoke the pushd command (with or without an argument), a space-...
kjo's user avatar
  • 3,105
1 vote
0 answers
79 views

Abort output in currently executing command in shell mode

Sometimes in shell I end up executing a command which results in too much output. For example, consider a wrong grep on a huge text file which results in 10,000 matches. The grep command completes ...
Miserable Variable's user avatar
0 votes
0 answers
277 views

run shell command interactively and insert final output into main buffer

I'm something of an Emacs newbie. I would like to run a shell script I've written and insert the output into the buffer I'm working in. But the script requires some interaction, so ideally I'd like ...
ShankarG's user avatar
  • 101
3 votes
0 answers
55 views

Using a sh-basic-offset value with a multiple of tab-width has side effects when building function using "C-c ("

When using a multiple of the tab-width value for sh-basic-offset, creating a function using the built-in command C-c ( removes characters from the expected result. That being said, I can create a ...
Phoenix's user avatar
  • 341
17 votes
1 answer
2k views

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

In shell-mode, a command like sudo CMD opens up a prompt in the echo area saying: [sudo] password for root: How does it know to do this? AFAIK, this behaviour cannot rise out of simply running sudo ...
extremeaxe5's user avatar
6 votes
1 answer
662 views

How to automatically kill a shell buffer when the shell process exits

In shell-mode when you exit the shell process (e.g. by typing exit) the buffer still hangs around (with the message "Process shell<1> finished"). How can I automatically kill the shell buffer when ...
halloleo's user avatar
  • 1,195
1 vote
1 answer
49 views

Is there a way to restrict history in shell-mode?

I run lots of test in shell-mode because I love being able to search through the history. However, some of these tests print lots of info to stdout and will cause my memory usage to go through the ...
tomcat's user avatar
  • 345
0 votes
2 answers
161 views

Shell-mode execute script every time a shell is invoked

I have changed the emacs-shell mode shell to WSL ubuntu but however, the prompt is not very user-readable. For this reason I would like to execute a script that changes it so that its more readable ...
Teererai Marange's user avatar
7 votes
3 answers
2k views

Emacs: How to clear a subshell screen?

In Emacs interactive subshell, when I type clear, the screen is not cleared as it should do in a normal Ubuntu Terminal, for example. When I press Ctrl + l(twice if the screen is full), the screen ...
Billal Begueradj's user avatar
0 votes
1 answer
362 views

emacs 25 shell-mode tab auto-completion issue with ksh

I have upgraded to Emacs 25.3 from 24. This issue only appears in the ksh. I've found that when I use bash then all is good. I find that in shell-mode when I hit tab to perform completion of the rest ...
ali hodgkiss's user avatar
3 votes
2 answers
756 views

how to watch and cat and grep with emacs

This doesn't seem to work in M-x shell $ watch 'grep "FIX" /tmp/output | tail -n 5' I see Every 2.0s: grep "FIX" /tmp/output | tail -n 5 and I see My-hostname.local: Tue Aug 28 19:09:22 2018 on ...
american-ninja-warrior's user avatar
1 vote
2 answers
825 views

Shell mode: moving through the command history

In a shell in a terminal (Gnome Terminal + bash), the up and down keys allow me to browse through my command history. In shell-mode inside emacs, the up and down keys move around the buffer, which is ...
blueFast's user avatar
  • 295
3 votes
1 answer
139 views

Shell mode does not do autocompletion for loaded functions

When running in a terminal, the shell does auto-completion even for loaded functions: $ check-<tab><tab> check-bios-nx check-dirty check-language-support check-...
blueFast's user avatar
  • 295
0 votes
0 answers
98 views

No tty in shell buffers in Carbon Emacs on High Sierra

I've been using the Carbon Emacs port of Emacs, which is based on Emacs 22, for many years. I know it's way out of date and unmaintained, but I have a huge collection of home-grown extensions that I ...
Barmar's user avatar
  • 101
0 votes
1 answer
85 views

Shell buffer echoes partial long lines

I've written a command that ssh-es to a remote host and runs an interactive command there. Something like: (defun remote-command () (interactive) (pop-to-buffer (get-buffer-create "*remote-...
Sean's user avatar
  • 919
9 votes
2 answers
274 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: ...
Anton's user avatar
  • 163
0 votes
1 answer
495 views

from the spacemacs shell, how do I edit a file in a new buffer in the main window?

I open a new shell using space-'. From that shell window I can type ls to see files. Let's say I want to edit ~/.zshrc. From the shell prompt, what do I type to edit that file in a new buffer in the ...
hnzix's user avatar
  • 1
1 vote
1 answer
197 views

shell-mode: `C-a` moves point to beginning of line instead of after prompt

Usually C-a moves point to just after the prompt: andreas@my-computer:~/some/folder $ #here but occasionally something happens and C-a starts to the beginning of line: andreas@my-computer:~/some/...
Andreas Jansson's user avatar
1 vote
0 answers
104 views

comint-input-ring-size ignored in shell-mode

I am trying to change comint-input-ring-size in shell mode in Emacs. The comint-input-file-name is correctly set to ~/.bash_history file which is a big file (around 5000 commands). However, if I set ...
Sundar Venkataraman's user avatar
0 votes
1 answer
565 views

Shell IO Behavior For Emacs' Shells

The GNU page for Eshell says that Eshell is not a replacement for system shells such as bash or zsh. Use Eshell when you want to move text between Emacs and external processes; if you only want to ...
Steven Tammen's user avatar
1 vote
1 answer
233 views

How to write a helm function to select only from shell buffers

I recently switched from ido to helm. Now I'm using helm-buffers-list to select buffers. Additionally I want to create a customised helm-buffers-list function which allows me only to select from ...
halloleo's user avatar
  • 1,195
1 vote
2 answers
753 views

How to disable show-trailing-whitespace in emacs shell?

I have set show-trailing-whitespace as default in my .emacs file but I don't want it to work on shell and some specific buffer. I can disable it manually every time I open an emacs shell but I want ...
Deepanshu Shukla's user avatar
4 votes
1 answer
161 views

EMACS shell mode that supports annotations

I often find myself doing things like installations or debugging where I would like to be able to work in shell mode but be able to insert annotations as I go. BBEdit has something like this but ...
Charlie Martin's user avatar
4 votes
2 answers
3k views

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

Windows 10, Emacs 25.1 In my init.el (define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring) But when I start emacs I get error: Symbol's value as variable is void: shell-mode-map
user8542613's user avatar
0 votes
1 answer
164 views

Why does `M-x shell-mode` now always/usually open in a different window?

Since a relatively recent laptop re-install, whenever I M-x shell-mode (usually with the default shell buffer already running somewhere), the shell doesn't appear in the currently active window, ...
Mark's user avatar
  • 1,389
6 votes
1 answer
1k views

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

Let's say that I run a process in the foreground, I then wish to pause it, and maybe assign it to the background. In normal C-shell, it is very easily done. I just press C-z, and then I input the ...
user1134991's user avatar
0 votes
0 answers
192 views

Sending command from bash in shell-mode, and knowing buffer name

My specific goal is setting 'vc-mode from the $PROMPT1 snippet so that the mode line will show useful VC info in shell-mode. I can use emacsclient -e '(setq vc-mode "foo")' but that's not quite ...
Mark's user avatar
  • 1,389
2 votes
2 answers
1k views

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

I am using emacs s 23.1.1. I have started to really use in real-earnest the shell, in order to minimize the amounts of time I am out of emacs. However, the bind-keys are emacs based. Which is good, ...
user1134991's user avatar