Emacs and shellcheck #

Julia Evans had a great talk called Making Hard Things Easy. One of the takeaways for me was that I should be using tools for parts of a system I find hard to remember. In particular, when writing bash scripts I should be using shellcheck.

It turns out Emacs 29 has support for shellcheck, and older versions of Emacs can use the flymake-shellcheck page.

To set it up in Emacs 29:

(use-package flymake
  :bind (("H-e" . flymake-show-project-diagnostics)))

(use-package sh-script
  :hook (sh-mode . flymake-mode))

I use consult for navigating my errors, and I want to make errors more noticable in the mode line, so my flymake configuration is:

(use-package flymake
  :bind (("H-e" . my/consult-flymake-project))
  (defun my/consult-flymake-project ()
    (consult-flymake t))
  (flymake-suppress-zero-counters t)
  (defface my/flymake-modeline-error-echo
    '((t :inherit 'flymake-error-echo :background "red"))
    "Mode line flymake errors")
  (put 'flymake-error 'mode-line-face 'my/flymake-modeline-error-echo)
  (defface my/flymake-modeline-warning-echo
    '((t :inherit 'flymake-warning-echo :background "orange"))
    "Mode line flymake warnings")
  (put 'flymake-warning 'mode-line-face 'my/flymake-modeline-warning-echo))

It's too early to know what other tweaks I might want, but so far it's alerted me to several errors in my shell scripts.

Update: [2023-10-07] Comments on HN pointed to bash-language-server which works with emacs lsp or eglot.