reddit / emacs
Improving shell in emacs
omeow · 2022-01-24 04:48
Hello,
Rather recently, I am getting into integrating emacs shell into my workflow. I found that `shell` works best for me. I tried `e-shell` but it did not render very well (am I missing something here).
I would like to improve my shell experience and I was hoping for some help on that front. Specifically.
- Using, something like `ls` in my default shell color codes the directories and files. But shell in emacs doesn't do that. (I am using zsh shell default.)
- The shell quotes every command. So typing `ls` will first print `ls` then the output. I will like to avoid that.
- Somewhat asinine of me, but I tried to invoke `nano` in side emacs shell. But then I couldn't terminate the process and had to kill the shell. Is there a way around it?
- Is it advisable to run tmux in the shell?
Thank you very much for your time and any suggestions towards shell customization is welcome!
bravosierrasierra · 2022-01-24 06:15
imho: vterm is only one usable terminal solution for emacs without any compromise. Without it i need external terminals.
omeow · 2022-01-24 06:43
Thank you. I will check it out. It looks very promising based on the emacs conf video!
omeow · 2022-01-24 07:49
So, I just installed vterm from melpa. I didn't customize anything.
​
After the term buffer fills up the cursor moves to the center of the buffer instead of the lowest position at the prompt.
Is this something that will get fixed with customization or do I need to do something else?
bravosierrasierra · 2022-01-24 08:18
On my macos and linux workstations it just works. May be you need restart emacs? It use external libvterm library, may be you have obsolete dependencies?
jsled · 2022-01-24 12:13
I too have never seen this; vterm works amazing out of the box, for me, on multiple systems.
_viz_ · 2022-01-24 13:43
1. Read the docstring of ansi-color-for-comint-mode.
2. You are looking for comint-process-echoes. But note that changing
it can make certain commands not work (e.g., racket) but this is
more an exception.
3. You have three options I think: (a) M-! pkill nano RET, (b) C-c C-z and
kill the process (use jobs+kill), and (c) I wrote the following command
to pass keystrokes to the underlying command, it is not perfect but
it gets the job done most of the time:
(defun vz/shell-send-keysequence-to-process (key)
"Send keysequence to current running process."
(interactive "sPress keysequence:")
(comint-send-string (get-buffer-process (current-buffer)) key))
4. Why tmux? Let Emacs handle the window management and you can
always create multiple shell buffers. For long running processes,
I tend to prefer opening st but I should probably look into using
abduco(1) for this instead.
ieure · 2022-01-24 16:37
You can also use Proced (`M-x proced RET`). It's terrific, and one of the seemingly lesser known Emacs features.
nicholas_hubbard · 2022-01-24 19:37
I have been extremely satisfied with using plain shell mode combined with [shx](https://github.com/riscy/shx-for-emacs). With shx I can open a file directly from the shell with `:edit`, and ssh with `:ssh`. I find that a plain old shell running bash when combined with emacs is just so powerful.
_viz_ · 2022-01-25 03:19
It certainly is! Every time I use top, I miss proced. proced has an excellent major mode menu so you don't have to remember any keys (which is a plus in my book ;-).
squirelpower · 2022-01-25 12:25
Regarding 4), that's what got me into developing dtache https://gitlab.com/niklaseklund/dtache. Could be an alternative if you want to avoid leaving Emacs :)
wargxs · 2022-01-26 12:31
That is amazing!
omeow · 2022-01-27 05:45
just a quick question. did you do the vterm shell-side configuration as explained in the vterm github page?
omeow · 2022-01-30 04:29
Just a quick question. Did you do the shell-side customization discussed on the vterm github page?
bravosierrasierra · 2022-01-30 12:45
yes. from my bashrc:
# https://github.com/akermu/emacs-libvterm
vterm_printf(){
if [ -n "$TMUX" ]; then
# Tell tmux to pass the escape sequences through
# (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
function clear(){
vterm_printf "51;Evterm-clear-scrollback";
tput clear;
}
PROMPT_COMMAND='echo -ne "\033]0;\h:\w\007"'
vterm_prompt_end(){
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
}
PS1=$PS1'\[$(vterm_prompt_end)\]'
# export PS1="\D{%a %d-%m %H:%M}, \W $ "'\[$(vterm_prompt_end)\]'
fi