-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellcheck.kak
76 lines (67 loc) · 2.75 KB
/
shellcheck.kak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copied from https://github.com/whereswaldon/shellcheck.kak (Unlicense)
######################
# Internal utilities #
######################
define-command -hidden -override -docstring "check whether shellcheck is installed" shellcheck-check-installed %{
evaluate-commands %sh{
if command -v shellcheck > /dev/null 2>&1; then
printf "set-option window shellcheck_installed true\n"
else
printf "set-option window shellcheck_installed false\n"
fi
}
}
define-command -hidden -override -docstring "populate options with shellcheck version information" shellcheck-parse-version %{
evaluate-commands %sh{
version="$(shellcheck -V|egrep 'version:'|tr -s ' '|cut -d' ' -f2)"
printf "set-option window shellcheck_major_version %d\n" "$(echo "$version" | cut -d'.' -f 1)"
printf "set-option window shellcheck_minor_version %d\n" "$(echo "$version" | cut -d'.' -f 2)"
printf "set-option window shellcheck_patch_version %d\n" "$(echo "$version" | cut -d'.' -f 3)"
}
echo -debug "Using shellcheck v%opt{shellcheck_major_version}.%opt{shellcheck_minor_version}.%opt{shellcheck_patch_version}"
}
define-command -hidden -override -docstring "enable shellcheck in the current window" shellcheck-configure-window %{
set window lintcmd %sh{
# format like gcc, check files other than the current buffer if they are 'source'd
flags="-f gcc -x"
# if version >= v0.4.7
if [ "$kak_opt_shellcheck_minor_version" -ge 4 ] && [ "$kak_opt_shellcheck_patch_version" -ge 7 ]; then
# enable warnings from sourced files
flags="$flags -a"
fi
echo "shellcheck $flags"
}
lint
hook -group shellcheck window BufWritePre .* %{
lint
}
}
###############################
# Externally-visible commands #
###############################
define-command -override -docstring "enable shellcheck in the current window" shellcheck-enable %{
evaluate-commands %sh{
if $kak_optshellcheck_installed; then
echo "shellcheck-parse-version"
echo "shellcheck-configure-window"
else
echo "echo -debug 'Missing shellcheck executable'"
fi
}
}
define-command -override -docstring "disable shellcheck in the current window" shellcheck-disable %{
lint-hide-diagnostics
remove-hooks window shellcheck
}
##################
# Initialization #
##################
declare-option -hidden int shellcheck_major_version
declare-option -hidden int shellcheck_minor_version
declare-option -hidden int shellcheck_patch_version
declare-option -hidden bool shellcheck_installed
hook global WinSetOption filetype=sh %{
# check whether binary exists
shellcheck-check-installed
shellcheck-enable
}