2016-01-06 05:21:55 +00:00
|
|
|
#+TITLE: Shell Scripts layer
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2019-05-07 08:21:07 +00:00
|
|
|
#+TAGS: dsl|layer|programming|script
|
2019-05-05 17:26:40 +00:00
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
[[file:img/fish.png]]
|
|
|
|
|
2019-05-07 20:05:06 +00:00
|
|
|
* Table of Contents :TOC_5_gh:noexport:
|
2017-05-22 14:16:12 +00:00
|
|
|
- [[#description][Description]]
|
2017-08-28 21:58:10 +00:00
|
|
|
- [[#features][Features:]]
|
2017-05-22 14:16:12 +00:00
|
|
|
- [[#install][Install]]
|
2019-01-03 10:53:34 +00:00
|
|
|
- [[#layer][Layer]]
|
2017-05-22 14:16:12 +00:00
|
|
|
- [[#linting][Linting]]
|
2016-11-12 21:08:57 +00:00
|
|
|
- [[#style-checking][Style checking]]
|
2019-09-28 20:04:51 +00:00
|
|
|
- [[#backends][Backends]]
|
|
|
|
- [[#shell-script-mode][Shell-script-mode]]
|
|
|
|
- [[#lsp][LSP]]
|
2018-12-05 03:03:03 +00:00
|
|
|
- [[#key-bindings][Key bindings]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
* Description
|
|
|
|
This simple layer adds support for shell scripting.
|
|
|
|
|
2016-01-18 03:06:04 +00:00
|
|
|
Supported scripting files:
|
|
|
|
- =.sh=
|
2015-06-10 16:44:30 +00:00
|
|
|
- =.fish=: [[https://github.com/fish-shell/fish-shell][fish shell]]
|
|
|
|
|
2015-06-10 21:16:01 +00:00
|
|
|
*Note:* For Windows scripting see the layer =windows-scripts=
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2017-08-28 21:58:10 +00:00
|
|
|
** Features:
|
2016-02-10 19:48:29 +00:00
|
|
|
- Auto-completion using [[https://github.com/Alexander-Miller/company-shell][company-shell]]
|
2018-10-23 14:18:21 +00:00
|
|
|
- =Sh= scripts linting using [[https://www.shellcheck.net/][shellcheck]]
|
2016-11-12 21:08:57 +00:00
|
|
|
- =Sh= scripts style checking using [[https://github.com/openstack-dev/bashate][bashate]]
|
2019-01-03 10:53:34 +00:00
|
|
|
- Support for the [[https://langserver.org/][Language Server Protocol]] (experimental)
|
2016-02-10 19:48:29 +00:00
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
* Install
|
2019-01-03 10:53:34 +00:00
|
|
|
** Layer
|
2016-01-06 05:21:55 +00:00
|
|
|
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
|
|
|
add =shell-scripts= to the existing =dotspacemacs-configuration-layers= list in this
|
|
|
|
file.
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2016-06-30 06:33:53 +00:00
|
|
|
** Linting
|
|
|
|
In order to enable =sh= scripts linting, install [[https://www.shellcheck.net/][shellcheck]].
|
|
|
|
|
2016-11-12 21:08:57 +00:00
|
|
|
** Style checking
|
|
|
|
In order to enable =sh= scripts style checking, install [[https://github.com/openstack-dev/bashate][bashate]].
|
|
|
|
|
2019-09-28 20:04:51 +00:00
|
|
|
** Backends
|
|
|
|
You have the choice between two different backends
|
|
|
|
with different setup instructions and different capabilities.
|
2019-01-03 10:53:34 +00:00
|
|
|
|
2019-09-28 20:04:51 +00:00
|
|
|
*** Shell-script-mode
|
|
|
|
This is the recommended way for working with shell scripts in emacs. It works
|
|
|
|
by using an emacs major mode.
|
2019-01-03 10:53:34 +00:00
|
|
|
|
2019-09-28 20:21:51 +00:00
|
|
|
It supports =bash= and =fish= shell scripts.
|
|
|
|
|
2019-09-28 20:04:51 +00:00
|
|
|
No additional setup is necessary.
|
2019-01-03 10:53:34 +00:00
|
|
|
|
2019-09-28 20:04:51 +00:00
|
|
|
*** LSP
|
|
|
|
This backend uses an external server to provide the various IDE integrations
|
|
|
|
and a more modern UI integration in =spacemacs=.
|
|
|
|
|
2019-09-28 20:21:51 +00:00
|
|
|
However it only supports working with =bash= scripts.
|
|
|
|
|
2019-09-28 20:04:51 +00:00
|
|
|
It requires installing the external server via:
|
2019-01-03 10:53:34 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC sh
|
|
|
|
npm i -g bash-language-server
|
|
|
|
#+END_SRC
|
|
|
|
|
2019-09-30 04:49:44 +00:00
|
|
|
Enable the =lsp= layer to activate this backend as well as setting the layer
|
|
|
|
variable =shell-scripts-backend=:
|
2019-09-28 20:04:51 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC elisp
|
|
|
|
(shell-scripts :variables shell-scripts-backend 'lsp)
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
You can find further information about the project at its [[https://github.com/mads-hartmann/bash-language-server][GitHub page]].
|
2019-01-03 10:53:34 +00:00
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
* Key bindings
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
| Key binding | Description |
|
2016-01-08 14:37:39 +00:00
|
|
|
|-------------+-----------------------------------------------------------|
|
|
|
|
| ~SPC m \~ | insert end-of-line backslashes to the lines in the region |
|
2017-08-05 22:10:39 +00:00
|
|
|
| ~SPC i !~ | insert shebang in a script file |
|
|
|
|
| ~SPC m i !~ | insert shebang in a script file |
|
|
|
|
| ~SPC m i c~ | insert switch case statement if supported by shell |
|
|
|
|
| ~SPC m i i~ | insert if statement if supported by shell |
|
|
|
|
| ~SPC m i f~ | insert function definition if supported by shell |
|
|
|
|
| ~SPC m i o~ | insert for loop if supported by shell |
|
|
|
|
| ~SPC m i e~ | insert an indexed for loop if supported by shell |
|
|
|
|
| ~SPC m i w~ | insert while loop if supported by shell |
|
|
|
|
| ~SPC m i r~ | insert repeat loop if supported by shell |
|
|
|
|
| ~SPC m i s~ | insert select loop if supported by shell |
|
|
|
|
| ~SPC m i u~ | insert until loop if supported by shell |
|
|
|
|
| ~SPC m i g~ | insert a getopts while loop if supported by shell |
|