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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
" Vim syntax file
" Language: Debian preseed
" Maintainer: cos <cos>, https://www.netizen.se/#contact
" Last Change: 2023 Nov 10
" Remark: https://wiki.debian.org/DebianInstaller/Preseed
" quit when a syntax file was already loaded
if exists('b:current_syntax')
finish
endif
" Allow user defined questions to have their shell script argument highlighted
" as sh. Please see ':help preseed_add_sh_pattern' for an example.
let s:shell_question_pattern = '\(preseed/\(early_command\|include_command\|late_command\)\|partman/early_command\)'
let shell_pattern_start='^\s*[[:alnum:]._-]\+\s\+'
if exists('preseed_add_sh_pattern')
let shell_pattern_start ..= '\(' . s:shell_question_pattern . '\|' . preseed_add_sh_pattern . '\) string'
else
let shell_pattern_start ..= s:shell_question_pattern . ' string'
endif
let shell_pattern_end='\([^\\]$\|^$\)'
" The syntax of each line in a preseed file follows:
" <owner> <question name> <question type> <value>
" Lets sloppily refer to them as columns.
" Out in the wild, there appears to be two preseed questions which fail to
" match the syntax rules. According to preseed.debian.net, these two are:
"
" debian-installer/shell-plugin and sitesummary-client/nagios-server
"
" The first one takes the `terminal` question type (rather than `boolean`,
" `string`, `password`, `select`, `multiselect` or `note`). Attempting to ask
" about this on #debian-boot gave the classic (non-)warm welcoming from one of
" the regulars there. That person claimed to have investigated the issue and
" stated that it is correct as it is. Followed up with a polite but clear
" instruction to shut-up.
"
" The second one is described as an internal hidden debconf question, and has
" 'db_get' injected between the owner and the question name fields. That could
" either be a clever hack or a bug. No investigation has been done to figure
" out which.
" Create clusters for two of these four columns of a preseed line.
syntax cluster preseedSecond contains=preseedQuestion,preseedOwnerLC
syntax cluster preseedThird contains=preseedBooleanType,preseedStrLikeType,preseedMultiSelType,preseedNote,preseedSelectType,preseedQuestionLC
" Highlight shell syntax for include_command and friends. This is not fully
" correct for multi-line arguments, as line continuations are flattened prior
" to the argument being given to the shell as one single line. Reusing sh.vim
" gets close enough to be useful though. Any patches with improvements are
" welcome.
syntax include @Sh syntax/sh.vim
" Define the highlighting. Doesn't map perfectly to the group's intents, but
" arguably close enough?
" First column, <owner>
hi! def link preseedOwner Label
hi! def link preseedShellOwner Label
" Second column, <question name>
hi! def link preseedQuestion Identifier
hi! def link preseedShellQuestion Special
hi! def link preseedShellStr Type
" Third column, <question type>
hi! def link preseedBooleanType Type
hi! def link preseedMultiSelType Type
hi! def link preseedNote Type
hi! def link preseedSelectType Type
hi! def link preseedStrLikeType Type
" Fourth column, <value>
hi! def link preseedBooleanVal Special
hi! def link preseedMultiSelVal Special
hi! def link preseedStrLikeVal String
hi! def link preseedVal String
hi! def link preseedSelectVal Special
hi! def link preseedMultiSelSep Operator
hi! def link preseedComment Comment
" Line Continuation
hi! def link preseedOwnerLC Operator
hi! def link preseedQuestionLC Operator
hi! def link preseedBooleanLC Operator
hi! def link preseedMultiSelLC Operator
hi! def link preseedStrLikeLC Operator
" Add the syntax matching rules.
" First, <owner>
sy match preseedOwner /^\s*[[:alnum:]._-]\+\(\s\|$\)/ nextgroup=@preseedSecond,preseedOwnerLC
" Second, <question name>
sy match preseedQuestion contained "\s*\([[:alnum:]._-]\+/\)\+[[:alnum:]._-]\+\(\s\|$\)" nextgroup=@preseedThird,preseedQuestionLC
" Third, <question type>
" (boolean, multiselect, note, password, select, string)
sy match preseedBooleanType contained /\s*boolean\(\s\|$\)/ nextgroup=preseedBooleanVal,preseedBooleanLC
sy match preseedMultiSelType contained /\s*multiselect\(\s\|$\)/ nextgroup=preseedMultiSelVal,preseedMultiSelLC
sy match preseedNote contained /\s*note$/
sy match preseedSelectType contained /\s*select\(\s\|$\)/ nextgroup=preseedSelectVal,preseedSelectLC
sy match preseedStrLikeType contained /\s*\(password\|string\)\(\s\|$\)/ nextgroup=preseedStrLikeVal,preseedStrLikeLC
" Fourth, <value>
sy match preseedBooleanVal contained /\s*\(false\|true\)/
sy match preseedMultiSelVal contained /.*/me=e contains=preseedMultiSelSep
sy match preseedMultiSelVal contained /.*\\/me=e-1 contains=preseedMultiSelSep nextgroup=preseedMultiSelLC
sy match preseedMultiSelSep contained /,/
sy match preseedSelectVal contained /.*/
sy match preseedStrLikeVal contained /.*/me=e
sy match preseedStrLikeVal contained /.*\\/me=e-1 nextgroup=preseedStrLikeLC
" Line continuation needs to be down here override other syntax.
sy match preseedBooleanLC contained /\s*\\$/ nextgroup=preseedBooleanVal,preseedBooleanLC skipnl
sy match preseedMultiSelLC contained /\\$/ nextgroup=preseedMultiSelVal skipnl
sy match preseedOwnerLC contained /\s*\\$/ nextgroup=@preseedSecond skipnl
sy match preseedQuestionLC contained /\s*\\$/ nextgroup=@preseedThird skipnl
sy match preseedSelectLC contained /\s*\\$/ nextgroup=preseedSelectVal,preseedSelectLC skipnl
sy match preseedStrLikeLC contained /\\$/ nextgroup=preseedStrLikeVal skipnl
" Argument to some questions is embedded shell script code.
execute 'syn region preseedShell start="' . shell_pattern_start . '"' . ' end="' . shell_pattern_end . '" contains=preseedShellOwner,@Sh'
syn region notShell start="whatever" end='\([^\x5c]\$\|^$\)' contains=preseedShellOwner,@Sh
sy match preseedShellOwner contained /^\s*[[:alnum:]._-]\+\(\s\|$\)/ nextgroup=preseedShellQuestion
sy match preseedShellQuestion contained "\s*\([[:alnum:]._-]\+/\)\+[[:alnum:]._-]\+\(\s\|$\)" nextgroup=preseedShellStr
sy match preseedShellStr contained /string/
" And comments must override everything else.
sy match preseedComment /^\s*#.*/
|