Shell operations

Table of Contents

For most heavy terminal work, I use the OS's terminal (particularly for establishing ssh and running emacs on the remote machine through the terminal). Here's a few features I find lacking in each of the options:

In shell and eshell you cannot use $ emacs --script to run a script (or so it seems).

On a separate note, you can use Ctrl-x Ctrl-e on the bash terminal to open up an editor and copy-paste a long command (that editor can be configured to be emacs).


I primarily use shell for moving/copying/transfering files and running executables.

  • Environment variables and aliases from my .bash_profile are imported in .emacs.d/
# export PS1='\h:\w$ '
source ~/.bash_profile
  • To start multiple shells: C-u M-x shell.
  • To use TAB for smart auto-completion, add (require 'shell).
  • If you hop directories using aliases, the shell will sometimes not catch up. Use (dirs) - I have this mapped to C-c d in shell-mode. Can use more aggressive tracking.

My shell configurations are here.

Some key bindings I use frequently:

task keybinding
invoke dirs C-c d
change directory to other window's directory C-u C-c c
clear shell C-c l


I understand eshell is also powerful and traversing through remote directories is easy as $ cd /ssh:user@host:dirname/. Also supports evaluation of emacs lisp expressions. However, eshell does not support input redirection.

In aprl-config, C-u C-c c is bound to change pwd to other window's directory, as above (in shell-mode).


term, ansi-term, and multi-term are also supposed to be powerful, even spawning emacs within emacs, but may require setting the environment variable (TERM) on the remote machine.

  • Default TERM is xterm-color in both OS X and Ubuntu; emacs works in term-mode works on my OS X (local machine) without setting TERM variable but not on my Ubuntu Linux (remote machine).
  • When logging onto my Ubuntu Linux from OS X, I can set export TERM=vt100 && emacs and this will enable me to run emacs within a term shell. However, this is not the prettiest option.
  • Term-mode has modes in the way that vi has modes: line-mode and char-mode. "In char mode, each character is sent directly to the inferior subshell, except for the Term escape character, normally C-c."
  • In char mode, C-x C-k kills emacs buffer running in term; in line mode C-x C-k offers to kill the super-emacs process running term-mode. To exit emacs running in term, M-x save-buffers-kill-emacs from char mode.

term and ansi-term are now similar, apparently. More info here.

My multi-term configuration is here.


Tramp-mode can also be used to edit files located on a remote machine: open file with /scp:username@host#port:/ (#port is optional) and all the customizations for the emacs on local machine will be available. This is useful for significant edits for files, but since file retrieval takes a little time not ideal for quick edits (probably faster to fire up emacs in terminal on remote machine).

Emacs pages: main aprl-config

Generated by Org-mode 9.2 with Emacs 26