[shell-scripts] Add shell-scripts-format-on-save

This commit is contained in:
Aaron L. Zeng 2021-08-02 15:26:54 -04:00 committed by duianto
parent cc8f3a3a32
commit 9e361eedc2
3 changed files with 11 additions and 1 deletions

View file

@ -4,7 +4,7 @@
[[file:img/fish.png]]
* Table of Contents :TOC_5_gh:noexport:
* Table of Contents :TOC_5_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
@ -30,6 +30,7 @@ Supported scripting files:
- =Sh= scripts linting using [[https://www.shellcheck.net/][shellcheck]]
- =Sh= scripts style checking using [[https://github.com/openstack-dev/bashate][bashate]]
- Support for the [[https://langserver.org/][Language Server Protocol]] (experimental)
- Automatic formatting via [[https://github.com/mvdan/sh][shfmt]]
* Install
** Layer

View file

@ -28,3 +28,6 @@
(defvar shell-scripts-backend (when (configuration-layer/layer-used-p 'lsp) 'lsp)
"The backend to use for IDE features.
When `lsp' layer is used, defaults to `lsp'.")
(defvar shell-scripts-format-on-save nil
"If non-nil, automatically format code with shfmt on save.")

View file

@ -33,6 +33,7 @@
insert-shebang
org
(sh-script :location built-in)
(shfmt :toggle shell-scripts-format-on-save)
))
(defun shell-scripts/init-company-shell ()
@ -99,6 +100,11 @@
(add-hook 'sh-mode-hook 'spacemacs//setup-shell)
(add-hook 'sh-mode-hook 'spacemacs//shell-scripts-setup-backend))))
(defun shell-scripts/init-shfmt ()
(use-package shfmt
:defer t
:init (add-hook 'sh-mode-hook 'shfmt-on-save-mode)))
(defun shell-scripts/post-init-ggtags ()
(add-hook 'sh-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))