Questions tagged [shell-mode]
is for the major mode for shell buffers. Use `C-c` prefix for accessing `M-x commands`.
90 questions
1
vote
1
answer
32
views
bash completion in emacs shell-mode with cygwin
I'm running cygwin bash in shell mode in emacs, but I don't get any completions, is there a way to set it up?
0
votes
1
answer
48
views
Bash sequence expression not expanded in org-babel session
Why are bash sequence expressions expanded in a normal org-babel source block but not in one attached to a session?
#+begin_src bash ...
2
votes
1
answer
80
views
Zsh running in Emacs shell hides partial lines (those lacking trailing newlines)
When running zsh under Emacs shell (M-x shell) with the stock zsh
config (zsh -f), partial lines are hidden from the output. Example:
Start emacs without config file:
$ emacs -q
Set
(setq explicit-...
1
vote
1
answer
75
views
git add not autocompleting filenames
I have a git repo and I'm trying to add some new files. If I do ls I can see the files. If I do git status, git tells me they're untracked but if I do git add and press tab, the autocomplete doesn't ...
1
vote
1
answer
301
views
Why does shell-mode truncate ps output?
Startup a fresh GTK emacs with no config with emacs -Q. Then run M-x shell. Then at the prompt:
$ ps -ef
Long commands will be truncated to the frame width, like this:
root 526315 2 0 15:...
0
votes
1
answer
103
views
comint-osc-process-output directory tracking does not seem to allow an empty hostname, causes problems on the Mac
I am using, per the Mastering Emacs blog, the following OSC7 command for directory tracking (in bash):
printf "\e]7;file://%s%s\e\\" "$HOSTNAME" "$PWD"
This mostly works,...
1
vote
1
answer
402
views
Shell echoing every command
(xpost from Unix Stack Exchange)
I'm using a local shell via an Emacs shell buffer. Seemingly at random, my shell will start echoing back every command I type before the rest of the output.
h ~ $ pwd
...
0
votes
2
answers
140
views
Is there a way to prevent keyboard echo while entering a password in shell-mode?
I have a test program that produces a lengthy output, so I ran it in "Shell".
However, at some point the test program prompts for a password, and when entering it, the characters are ...
1
vote
1
answer
121
views
How to display an svg string (not a file) in emacs
I have a python program that uses graphviz to generate an svg image that it prints out. When I run that in a shell buffer I see a textual representation of the svg image. I'd like to see instead the ...
0
votes
1
answer
54
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 ...
0
votes
1
answer
386
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 ...
2
votes
1
answer
413
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, ...
0
votes
0
answers
92
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 ...
0
votes
0
answers
38
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?
...
0
votes
0
answers
124
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-...
0
votes
1
answer
127
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 " ...
3
votes
1
answer
167
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 ...
4
votes
1
answer
203
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 ...
1
vote
1
answer
64
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 ...
0
votes
1
answer
513
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 #...
2
votes
1
answer
71
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 ...
1
vote
1
answer
702
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?
2
votes
1
answer
454
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 ...
0
votes
1
answer
58
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 ...
1
vote
1
answer
99
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=&...
5
votes
1
answer
292
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 ...
0
votes
0
answers
32
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 ...
1
vote
0
answers
272
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'...
2
votes
2
answers
861
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:/...
0
votes
0
answers
23
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-...
1
vote
0
answers
151
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 ...
1
vote
0
answers
527
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 ...
3
votes
0
answers
77
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 ...
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 ...
6
votes
1
answer
966
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 ...
1
vote
1
answer
61
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 ...
0
votes
2
answers
229
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 ...
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 ...
0
votes
1
answer
443
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 ...
4
votes
2
answers
1k
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 ...
1
vote
2
answers
1k
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 ...
3
votes
1
answer
198
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-...
0
votes
0
answers
107
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 ...
0
votes
1
answer
117
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-...
9
votes
2
answers
339
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:
...
0
votes
1
answer
534
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 ...
1
vote
1
answer
253
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/...
1
vote
0
answers
126
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 ...
0
votes
1
answer
620
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 ...
1
vote
1
answer
271
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 ...