This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+tools/shell/README.org

238 lines
8.8 KiB
Org Mode
Raw Normal View History

#+TITLE: Shell layer
2015-06-10 16:44:30 +00:00
[[file:img/shell.png]]
2018-09-19 03:54:47 +00:00
* Table of Contents :TOC_4_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description][Description]]
- [[#features][Features:]]
2017-05-22 14:16:12 +00:00
- [[#install][Install]]
- [[#configuration][Configuration]]
- [[#default-shell][Default shell]]
2018-05-27 21:50:16 +00:00
- [[#default-shell-position-width-and-height][Default shell position, width, and height]]
2017-05-22 14:16:12 +00:00
- [[#set-shell-for-term-and-ansi-term][Set shell for term and ansi-term]]
- [[#set-shell-for-multi-term][Set shell for multi-term]]
2017-05-22 14:16:12 +00:00
- [[#width-of-the-shell-popup-buffers][Width of the shell popup buffers]]
- [[#enable-em-smart-in-eshell][Enable em-smart in Eshell]]
- [[#protect-your-eshell-prompt][Protect your Eshell prompt]]
- [[#fish-shell-and-ansi-term][Fish shell and ansi-term]]
- [[#eshell][Eshell]]
- [[#key-bindings][Key bindings]]
- [[#multi-term][Multi-term]]
- [[#eshell-1][Eshell]]
2015-06-10 16:44:30 +00:00
* Description
This layer configures the various shells available in Emacs.
** Features:
2018-09-19 03:54:47 +00:00
- Shell integration
2015-06-10 16:44:30 +00:00
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =shell= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
* Configuration
2015-06-10 16:44:30 +00:00
** Default shell
Emacs supports three types of shell:
- the Emacs shell
- the inferior shell
- the terminal emulator
- the ANSI terminal emulator
You can find a quick introductions to them [[https://www.masteringemacs.org/article/running-shells-in-emacs-overview][here]].
2015-06-10 16:44:30 +00:00
To define the default shell you can set the layer variable =shell-default-shell=
to the following variables:
- =eshell=
- =shell=
- =term=
- =ansi-term=
- =multi-term=
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
(setq-default dotspacemacs-configuration-layers
'((shell :variables shell-default-shell 'eshell)))
2015-06-10 16:44:30 +00:00
#+END_SRC
The default shell is quickly accessible via a the default shortcut key ~SPC '~.
2015-06-10 16:44:30 +00:00
** Default shell position, width, and height
It is possible to choose where the shell should pop up by setting the variable
=shell-default-position= to either =top=, =bottom=, =left=, =right=, or =full=.
Default value is =bottom=. It is also possible to set the default height in
percents with the variable =shell-default-height=. Default value is =30=. You
can also set a default width in percents with the variable
=shell-default-width=, which has a default value of 30 and will take effect if
your shell is positioned on the left or the right.
2015-06-10 16:44:30 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((shell :variables
shell-default-position 'bottom
shell-default-height 30)))
(setq-default dotspacemacs-configuration-layers
'((shell :variables
shell-default-position 'right
shell-default-width 40)))
2015-06-10 16:44:30 +00:00
#+END_SRC
** Set shell for term and ansi-term
The default shell can be set by setting the variable =shell-default-term-shell=.
Default value is =/bin/bash=.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((shell :variables shell-default-term-shell "/bin/bash")))
2015-06-10 16:44:30 +00:00
#+END_SRC
** Set shell for multi-term
The default shell can be set by setting the variable =multi-term-program=.
Default value is =/bin/bash=.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((shell :variables multi-term-program "/bin/bash")))
#+END_SRC
** Width of the shell popup buffers
By default the popup buffer spans the full width of the current frame, if
you prefer to spans only the width of the current window then set the
layer variable =shell-default-full-span= to nil.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((shell :variables shell-default-full-span nil)))
#+END_SRC
** Enable em-smart in Eshell
From the =em-smart= documentation:
#+BEGIN_QUOTE
2018-09-19 03:54:47 +00:00
The best way to get a sense of what this code is trying to do is by
using it. Basically, the philosophy represents a blend between the
2018-09-19 03:54:47 +00:00
ease of use of modern day shells, and the review-before-you-proceed
mentality of Plan 9s 9term.
#+END_QUOTE
2018-09-19 03:54:47 +00:00
In a nutshell, when =em-smart= is enabled point wont jump at the end of the
buffer when a command is executed, it will stay at the same command prompt used
to execute the command. This allows to quickly edit the last command in the case
of a mistake. If there is no mistake and you directly type a new command then
the prompt will jump to the next prompt at the end of the buffer.
To enable =em-smart= put the following layer variable to non-nil:
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((shell :variables shell-enable-smart-eshell t)))
#+END_SRC
** Protect your Eshell prompt
Comint mode (Shell mode) has good support for Evil mode as it inhibits movement
commands over the prompt. This has the added benefit that Evil mode functions
work sensibly. E.g. you can press ~cc~ in normal state i.e.
=evil-change-whole-line= to kill the current input and start typing a new
command. In Eshell you also kill the prompt, which is often unintended.
By default this layer also protects the =eshell= prompt. If you want to
disable this protection you can set the variable =shell-protect-eshell-prompt=
to nil.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((shell :variables shell-protect-eshell-prompt nil)))
#+END_SRC
** Fish shell and ansi-term
Making =fish= shell to work with =ansi-term= may be a challenge, here are
some pointers to save you time to setup your environment correctly.
First be sure =~/.terminfo= is setup correctly by running:
#+BEGIN_SRC fish
2018-09-19 03:54:47 +00:00
tic -o ~/.terminfo $TERMINFO/e/eterm-color.ti
#+END_SRC
You can locate the =eterm-colors.ti= file with:
#+BEGIN_SRC fish
2018-09-19 03:54:47 +00:00
locate eterm-color.ti
#+END_SRC
Then setup your fish configuration file (usually at =~/.config/fish/config.fish=)
#+BEGIN_SRC fish
2018-09-19 03:54:47 +00:00
# emacs ansi-term support
if test -n "$EMACS"
set -x TERM eterm-color
end
# this function may be required
function fish_title
true
end
#+END_SRC
Finally you may need to toggle truncated lines for some prompts to work
correctly, in the function =dotspacemacs/user-config= of your dotfile add:
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
(add-hook 'term-mode-hook 'spacemacs/toggle-truncate-lines-on)
#+END_SRC
* Eshell
Some advanced configuration is setup for =eshell= in this layer:
- some elisp functions aliases for quick access
- =s= for =magit-status= in the current directory (when the =git= layer is
installed)
- =d= for =dired=
- =e= to find a file via a new buffer
2016-01-08 20:45:56 +00:00
- =z= for quickly jumping to a previously visited directory
- optional configuration for =em-smart= (see =Install= section for more info)
- support for visual commands via =em-term=
2017-04-25 15:42:58 +00:00
- working directory sensitive prompt via [[https://github.com/kaihaosw/eshell-prompt-extras][eshell-prompt-extras]]
- advanced help support via =esh-help= (enable =el-doc= support in eshell)
- add support for auto-completion via =company= (when the =auto-completion=
layer is installed)
- pressing ~i~ in normal state will automatically jump to the prompt
2015-06-10 16:44:30 +00:00
* Key bindings
| Key binding | Description |
2015-06-10 16:44:30 +00:00
|-------------+------------------------------------------------------------|
| ~SPC '~ | Open, close or go to the default shell |
2018-09-19 03:54:47 +00:00
| ~SPC p '~ | Open a shell in the projects root |
2015-06-10 16:44:30 +00:00
| ~SPC a s e~ | Open, close or go to an =eshell= |
| ~SPC a s i~ | Open, close or go to a =shell= |
| ~SPC a s m~ | Open, close or go to a =multi-term= |
| ~SPC a s t~ | Open, close or go to a =ansi-term= |
| ~SPC a s T~ | Open, close or go to a =term= |
2015-09-15 23:10:05 +00:00
| ~SPC m H~ | browse history with =helm= (works in =eshell= and =shell=) |
2015-06-10 16:44:30 +00:00
| ~C-j~ | next item in history |
| ~C-k~ | previous item in history |
*Note:* You can open multiple shells using a numerical prefix argument,
for instance pressing ~2 SPC '~ will a second default shell, the
2015-06-10 16:44:30 +00:00
number of shell is indicated on the mode-line.
*Note:* Use the universal prefix argument ~SPC u SPC '~ to open the shell
in the current buffer instead of a popup.
2015-06-10 16:44:30 +00:00
** Multi-term
| Key binding | Description |
|------------------------+--------------------------------|
| ~SPC m c~ | create a new multi-term |
| ~SPC m C~ | switch multi-term char mode |
| ~SPC m l~ | switch multi-term to line mode |
| ~SPC m n~ | go to next multi-term |
| ~SPC m N~ or ~SPC m p~ | go to previous multi-term |
| ~SPC p $ t~ | run multi-term shell in root |
** Eshell
| Key binding | Description |
|--------------------+--------------------------------------------|
| ~SPC m H~ or ~M-l~ | shell commands history using a helm buffer |