2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/sh/config.el -*- lexical-binding: t; -*-
|
2015-09-28 14:22:26 -04:00
|
|
|
|
2017-06-20 15:34:10 +02:00
|
|
|
(defvar +sh-builtin-keywords
|
2017-06-20 23:33:22 +02:00
|
|
|
'("cat" "cat" "cd" "chmod" "chown" "cp" "curl" "date" "echo" "find" "git"
|
2017-11-05 21:25:01 +01:00
|
|
|
"grep" "kill" "less" "ls" "make" "mkdir" "mv" "pgrep" "pkill" "pwd"
|
|
|
|
"rm" "sleep" "sudo" "touch")
|
|
|
|
"A list of common shell commands to be fontified especially in `sh-mode'.")
|
2017-06-20 15:34:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Plugins
|
|
|
|
;;
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! sh-script ; built-in
|
2018-05-25 00:46:11 +02:00
|
|
|
:mode ("\\.zunit\\'" . sh-mode)
|
|
|
|
:mode ("/bspwmrc\\'" . sh-mode)
|
2016-05-13 00:29:07 -04:00
|
|
|
:config
|
2018-06-15 12:30:56 +02:00
|
|
|
(set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
|
2018-06-15 16:07:24 +02:00
|
|
|
(set-repl-handler! 'sh-mode #'+sh/repl)
|
2017-06-20 15:34:10 +02:00
|
|
|
|
2016-04-20 01:50:55 -04:00
|
|
|
(setq sh-indent-after-continuation 'always)
|
|
|
|
|
2017-10-21 14:49:57 +02:00
|
|
|
;; recognize function names with dashes in them
|
2018-06-23 16:48:58 +02:00
|
|
|
(add-to-list 'sh-imenu-generic-expression
|
|
|
|
'(sh (nil "^\\s-*function\\s-+\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?" 1)
|
|
|
|
(nil "^\\s-*\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*()" 1)))
|
2017-10-21 14:49:57 +02:00
|
|
|
|
2018-04-23 00:03:28 -04:00
|
|
|
;; `sh-set-shell' is chatty about setting up indentation rules
|
|
|
|
(advice-add #'sh-set-shell :around #'doom*shut-up)
|
2018-02-02 20:46:02 -05:00
|
|
|
|
2017-06-20 15:34:10 +02:00
|
|
|
;; 1. Fontifies variables in double quotes
|
|
|
|
;; 2. Fontify command substitution in double quotes
|
|
|
|
;; 3. Fontify built-in/common commands (see `+sh-builtin-keywords')
|
|
|
|
(font-lock-add-keywords
|
|
|
|
'sh-mode `((+sh--match-variables-in-quotes
|
2017-11-05 21:25:49 +01:00
|
|
|
(1 'font-lock-constant-face prepend)
|
2017-06-20 15:34:10 +02:00
|
|
|
(2 'font-lock-variable-name-face prepend))
|
|
|
|
(+sh--match-command-subst-in-quotes
|
2017-10-18 18:24:25 +02:00
|
|
|
(1 'sh-quoted-exec prepend))
|
2017-06-20 23:33:22 +02:00
|
|
|
(,(regexp-opt +sh-builtin-keywords 'words)
|
2017-11-05 21:25:49 +01:00
|
|
|
(0 'font-lock-type-face append))))
|
2018-08-20 00:33:19 +02:00
|
|
|
;; 4. Fontify delimiters by depth
|
|
|
|
(add-hook 'sh-mode-hook #'rainbow-delimiters-mode)
|
2017-06-20 15:34:10 +02:00
|
|
|
|
2017-09-02 16:11:14 +02:00
|
|
|
;; autoclose backticks
|
|
|
|
(sp-local-pair 'sh-mode "`" nil :unless '(sp-point-before-word-p sp-point-before-same-p))
|
|
|
|
|
2017-05-28 16:12:28 +02:00
|
|
|
;; sh-mode has file extensions checks for other shells, but not zsh, so...
|
2017-02-19 18:57:16 -05:00
|
|
|
(defun +sh|detect-zsh ()
|
2017-06-20 16:18:27 +02:00
|
|
|
(when (or (and buffer-file-name
|
|
|
|
(string-match-p "\\.zsh\\'" buffer-file-name))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
2018-05-25 00:52:37 +02:00
|
|
|
(looking-at-p "^#!.+/zsh[$ ]")))
|
2017-02-19 18:57:16 -05:00
|
|
|
(sh-set-shell "zsh")))
|
2017-04-17 02:17:10 -04:00
|
|
|
(add-hook 'sh-mode-hook #'+sh|detect-zsh))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! company-shell
|
2017-03-19 22:47:50 -04:00
|
|
|
:when (featurep! :completion company)
|
2016-04-23 22:08:46 -04:00
|
|
|
:after sh-script
|
2017-03-20 16:32:29 -04:00
|
|
|
:config
|
2018-06-15 02:58:12 +02:00
|
|
|
(set-company-backend! 'sh-mode '(company-shell company-files))
|
2017-03-20 16:32:29 -04:00
|
|
|
(setq company-shell-delete-duplicates t))
|
2016-04-23 22:08:46 -04:00
|
|
|
|
2018-08-21 02:57:40 +02:00
|
|
|
|
2018-07-18 15:56:55 -04:00
|
|
|
(def-package! fish-mode
|
|
|
|
:when (featurep! +fish)
|
|
|
|
:defer t
|
2018-08-22 02:15:44 +02:00
|
|
|
:config (set-formatter! 'fish-mode #'fish_indent))
|