Skip to content

Commit 078d1b3

Browse files
Merge pull request #10 from michaelblyons/embed-inherited-shell
Add ST4 features
2 parents 8021de7 + 15afc9f commit 078d1b3

12 files changed

+413
-103
lines changed

.github/workflows/syntax.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ jobs:
2525
matrix:
2626
include:
2727
- build: 'latest'
28+
packages: master
2829
- build: 'stable'
29-
- build: 3211
30+
packages: v4193 # revert to 'binary' when Bash rewrite drops in stable
31+
- build: 4086
32+
packages: v4193 # Bash rewrite
3033
steps:
3134
- uses: actions/checkout@v4
3235
- uses: SublimeText/syntax-test-action@v2
3336
with:
3437
build: ${{ matrix.build }}
38+
default_packages: ${{ matrix.packages }}
3539
package_name: 'Crontab'
36-
dummy_syntaxes: source.shell

Bash (for Crontab).sublime-syntax

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
%YAML 1.2
2+
---
3+
name: Bash (for Crontab)
4+
scope: source.shell.bash.crontab
5+
version: 2
6+
hidden: true
7+
8+
extends: Packages/ShellScript/Bash.sublime-syntax
9+
10+
contexts:
11+
prototype:
12+
- meta_prepend: true
13+
- include: crontab-char-escapes
14+
15+
parameter-expansions:
16+
- meta_prepend: true
17+
- include: crontab-char-escapes
18+
19+
string-prototype:
20+
- meta_prepend: true
21+
- include: crontab-char-escapes
22+
23+
crontab-char-escapes:
24+
- match: '\\%'
25+
scope: constant.character.escape.crontab
26+
- match: '%'
27+
scope: constant.character.newline.crontab

Crontab.sublime-settings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010
"month": "region.bluish",
1111
"day-of-week": "region.yellowish",
1212
},
13+
14+
// Activate auto-complete for @-expressions
15+
"auto_complete_triggers":
16+
[
17+
{
18+
"characters": "@",
19+
"selector": "source.crontab",
20+
},
21+
],
1322
}

Crontab.sublime-syntax

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
---
33
name: Crontab
44
scope: source.crontab
5+
version: 2
56

67
file_extensions:
78
- tab
@@ -14,10 +15,6 @@ contexts:
1415
- include: variables
1516
- include: at-syntax
1617
- include: cron-syntax
17-
# Don't `invalid.illegal` in-process completions
18-
- match: '{{snippet_typing}}'
19-
- match: ^\s*\w+
20-
scope: invalid.illegal.crontab
2118

2219
###[ CRON EXPRESSIONS ]########################################################
2320

@@ -43,7 +40,7 @@ contexts:
4340
- meta_content_scope:
4441
meta.string.cron-expression.crontab
4542
meta.sequence.cron.minute.crontab
46-
- include: pop-nl
43+
- include: pop-eol
4744
- include: illegal-punctuation
4845
- include: cron-common
4946
- match: \b{{minute}}(-){{minute}}\b
@@ -52,13 +49,14 @@ contexts:
5249
1: punctuation.separator.sequence.crontab
5350
- match: \b{{minute}}\b
5451
scope: constant.numeric.integer.decimal.crontab
52+
- include: illegal-numbers
5553
- match: (?=[ \t])
5654
set: cron-hour-is-next
5755
- include: illegal-non-whitespace
5856

5957
cron-hour-is-next:
6058
- meta_content_scope: meta.string.cron-expression.crontab
61-
- include: pop-nl
59+
- include: pop-eol
6260
- include: cron-initial-comma
6361
- match: (?=\S)
6462
set: cron-hour
@@ -67,7 +65,7 @@ contexts:
6765
- meta_content_scope:
6866
meta.string.cron-expression.crontab
6967
meta.sequence.cron.hour.crontab
70-
- include: pop-nl
68+
- include: pop-eol
7169
- include: illegal-punctuation
7270
- include: cron-common
7371
- match: \b{{hour}}(-){{hour}}\b
@@ -76,13 +74,14 @@ contexts:
7674
1: punctuation.separator.sequence.crontab
7775
- match: \b{{hour}}\b
7876
scope: constant.numeric.integer.decimal.crontab
77+
- include: illegal-numbers
7978
- match: (?=[ \t])
8079
set: cron-day-of-month-is-next
8180
- include: illegal-non-whitespace
8281

8382
cron-day-of-month-is-next:
8483
- meta_content_scope: meta.string.cron-expression.crontab
85-
- include: pop-nl
84+
- include: pop-eol
8685
- include: cron-initial-comma
8786
- match: (?=\S)
8887
set: cron-day-of-month
@@ -91,7 +90,7 @@ contexts:
9190
- meta_content_scope:
9291
meta.string.cron-expression.crontab
9392
meta.sequence.cron.day-of-month.crontab
94-
- include: pop-nl
93+
- include: pop-eol
9594
- include: illegal-punctuation
9695
- include: cron-common
9796
- match: \b{{day_of_month}}(-){{day_of_month}}\b
@@ -102,6 +101,7 @@ contexts:
102101
captures:
103102
1: constant.numeric.integer.decimal.crontab
104103
2: invalid.deprecated.non-standard.crontab
104+
- include: illegal-numbers
105105
- match: \?
106106
scope: invalid.deprecated.non-standard.crontab
107107
- match: (?=[ \t])
@@ -110,7 +110,7 @@ contexts:
110110

111111
cron-month-is-next:
112112
- meta_content_scope: meta.string.cron-expression.crontab
113-
- include: pop-nl
113+
- include: pop-eol
114114
- include: cron-initial-comma
115115
- match: (?=\S)
116116
set: cron-month
@@ -119,7 +119,7 @@ contexts:
119119
- meta_content_scope:
120120
meta.string.cron-expression.crontab
121121
meta.sequence.cron.month.crontab
122-
- include: pop-nl
122+
- include: pop-eol
123123
- include: illegal-punctuation
124124
- include: cron-common
125125
- match: \b{{month}}(-){{month}}\b
@@ -128,6 +128,7 @@ contexts:
128128
1: punctuation.separator.sequence.crontab
129129
- match: \b{{month}}\b
130130
scope: constant.numeric.integer.decimal.crontab
131+
- include: illegal-numbers
131132
- match: \b({{words_month}})(-)({{words_month}})\b
132133
scope: constant.other.range.crontab
133134
captures:
@@ -138,11 +139,10 @@ contexts:
138139
scope: support.constant.month-name.crontab
139140
- match: (?=[ \t])
140141
set: cron-day-of-week-is-next
141-
- include: illegal-non-alpha
142142

143143
cron-day-of-week-is-next:
144144
- meta_content_scope: meta.string.cron-expression.crontab
145-
- include: pop-nl
145+
- include: pop-eol
146146
- include: cron-initial-comma
147147
- match: (?=\S)
148148
set: cron-day-of-week
@@ -151,7 +151,7 @@ contexts:
151151
- meta_content_scope:
152152
meta.string.cron-expression.crontab
153153
meta.sequence.cron.day-of-week.crontab
154-
- include: pop-nl
154+
- include: pop-eol
155155
- include: illegal-punctuation
156156
- include: cron-common
157157
- match: \b{{day_of_week}}(-){{day_of_week}}\b
@@ -162,6 +162,7 @@ contexts:
162162
captures:
163163
1: constant.numeric.integer.decimal.crontab
164164
2: invalid.deprecated.non-standard.crontab
165+
- include: illegal-numbers
165166
- match: \b({{words_day_of_week}})(-)({{words_day_of_week}})\b
166167
scope: constant.other.range.crontab
167168
captures:
@@ -174,22 +175,31 @@ contexts:
174175
scope: invalid.deprecated.non-standard.crontab
175176
- match: (?=[ \t])
176177
set: command-is-next
177-
- include: illegal-non-alpha
178178

179179
command-is-next:
180-
- include: pop-nl
180+
- include: pop-eol
181181
- match: \s+
182-
embed: scope:source.shell
183-
escape: (?=\n|$)
182+
embed: scope:source.shell.bash.crontab
183+
escape: (?=$|(?<!\\)%)
184+
- match: (?=%)
185+
set: command-stdin
186+
187+
command-stdin:
188+
- meta_content_scope: meta.string.stdin.crontab string.unquoted.crontab
189+
- include: pop-eol
190+
- match: \\%
191+
scope: constant.character.escape.crontab
192+
- match: '%'
193+
scope: constant.character.newline.crontab
184194

185195
at-syntax:
186196
# Keyword, then script embed
187197
- match: ^\s*((@){{keywords}})[ \t]+
188198
captures:
189199
1: constant.language.schedule.crontab
190200
2: punctuation.definition.variable.crontab
191-
embed: scope:source.shell
192-
escape: $
201+
embed: scope:source.shell.bash.crontab
202+
escape: (?=$)
193203
# Don't unhighlight keywords just because EOL
194204
- match: ^\s*((@){{keywords}})\b
195205
captures:
@@ -201,19 +211,7 @@ contexts:
201211
1: punctuation.definition.variable.crontab
202212
2: meta.completion.at.crontab
203213

204-
###[ MISCELLANEOUS ]###########################################################
205-
206-
comments:
207-
- match: ^\s*(?=#)
208-
push: comment
209-
210-
comment:
211-
- match: '#'
212-
scope: punctuation.definition.comment.crontab
213-
push:
214-
- meta_scope: comment.line.number-sign.crontab
215-
- include: pop-nl
216-
- include: pop-nl
214+
###[ ENVIRONMENT VARIABLES ]###################################################
217215

218216
variables:
219217
- match: ^([a-zA-Z0-9_]+)\s*(=)
@@ -223,33 +221,53 @@ contexts:
223221
push: variable-value
224222

225223
variable-value:
226-
- include: pop-nl
224+
- include: pop-eol
227225
- match: '"'
228226
scope: punctuation.definition.string.begin.crontab
229-
set:
230-
- meta_scope: string.quoted.double.crontab
231-
- match: '"'
232-
scope: punctuation.definition.string.end.crontab
233-
pop: true
227+
set: string-body-double
234228
- match: "'"
235229
scope: punctuation.definition.string.begin.crontab
236-
set:
237-
- meta_scope: string.quoted.single.crontab
238-
- match: "'"
239-
scope: punctuation.definition.string.end.crontab
240-
pop: true
230+
set: string-body-single
241231
- match: \S
232+
push: string-body-unquoted
233+
234+
string-body-double:
235+
- meta_scope: meta.string.crontab string.quoted.double.crontab
236+
- match: '"'
237+
scope: punctuation.definition.string.end.crontab
238+
pop: 1
239+
240+
string-body-single:
241+
- meta_scope: meta.string.crontab string.quoted.single.crontab
242+
- match: "'"
243+
scope: punctuation.definition.string.end.crontab
244+
pop: 1
245+
246+
string-body-unquoted:
247+
- meta_scope: meta.string.crontab string.unquoted.crontab
248+
- match: (?=\s*$)
249+
pop: 1
250+
251+
###[ MISCELLANEOUS ]###########################################################
252+
253+
comments:
254+
- match: ^\s*(?=#)
255+
push: comment
256+
257+
comment:
258+
- match: '#'
259+
scope: punctuation.definition.comment.crontab
242260
push:
243-
- meta_scope: string.unquoted.crontab
244-
- match: (?=\s*$)
245-
pop: true
261+
- meta_scope: comment.line.number-sign.crontab
262+
- include: pop-eol
263+
- include: pop-eol
246264

247265
illegal-punctuation:
248266
- match: \*{2,}|[/,?-]{2,}|,(?=[ \t])
249267
scope: invalid.illegal.crontab
250268

251-
illegal-non-alpha:
252-
- match: (?i:[^a-z\s]+)
269+
illegal-numbers:
270+
- match: \d+
253271
scope: invalid.illegal.crontab
254272

255273
illegal-non-whitespace:
@@ -258,9 +276,9 @@ contexts:
258276

259277
###[ PROTOTYPE ]###############################################################
260278

261-
pop-nl:
279+
pop-eol:
262280
- match: $\n?
263-
pop: true
281+
pop: 1
264282

265283
###############################################################################
266284

Lint Crontab.sublime-build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"selector": "source.crontab",
3+
"cmd": ["crontab", "-T", "$file"],
4+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Crontab for Sublime Text 3
1+
# Crontab for Sublime Text
22

33
[![GitHub license](https://img.shields.io/github/license/michaelblyons/SublimeSyntax-Crontab.svg)](https://github.com/michaelblyons/SublimeSyntax-Crontab/blob/master/LICENSE)
44
[![GitHub release](https://img.shields.io/github/release/michaelblyons/SublimeSyntax-Crontab.svg)](https://GitHub.com/michaelblyons/SublimeSyntax-Crontab/releases/)
@@ -12,7 +12,7 @@
1212
- Color-coded underline for `cron` expressions.
1313
- Completions for `cron` expressions and enums like month names.
1414
- Hover on a `cron` expression for an explanation.
15-
- Shell syntax highlighting for cron commands
15+
- Shell syntax highlighting for `cron` commands
1616
- Comment and uncommenting lines using <kbd>Ctrl</kbd>+<kbd>/</kbd> or <kbd>Cmd</kbd>+<kbd>/</kbd>.
1717

1818
## Installation
@@ -23,11 +23,11 @@
2323

2424
## Todos
2525

26-
- [ ] Alert on unescaped usage of `%` in crontab line.
2726
- [ ] Provide a template file of things to do when creating a crontab file.
2827
- [ ] Additional "system" crontab syntax with user/group support.
2928
- [x] Options to change or disable rainbow underlines. (#4)
3029
- [x] Continuous integration
30+
- [ ] Autocomplete works after `,` and `-`
3131

3232
## Credits/Acknowledgements
3333

0 commit comments

Comments
 (0)