-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyntaxDemo.bunch
432 lines (374 loc) · 11.2 KB
/
SyntaxDemo.bunch
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
---
# certain front matter keys are well known and cause bunch to do stuff
title: Documentation
shortcut: d
open at: 10am
schedule if: E1FD327A-E6D6-556D-984F-9E927EC53BEF
title prefix: 📱
ignore: true
ignore if:
# all other keys assign variables
frontvar: Some new value
srcdir: ~/src/myproject
varfromscript: $ echo thevalue
web site: close after:https://bunchapp.co
onoff: off
somevar:
---
/*
TODO
-[x] figure out how to do App Completions
-[ ] idea for Brett, a url scheme to validate the syntax of a file
-[ ] display snippet
-[x] frontmatter completion
-[x] get all valid commands for Command Completions
-[x] autocomplete embedded fragment ids
-[ ] embedded fragment completion doesn't work inside of a dictionary
-[x] autocomplete snippet files
-[ ] autocomplete fragment ids from a snippet
-[x] completion on variable transformations ie raw in ${myvar/raw}
-[X] make sure Comment Line and Comment Start Block commands work
-[ ] figure out how to set the default indenting to soft tabs of size 4
-[ ] dialog snippet, how can I insert snippet stuff after the autoinserted closing bracket?
-[ ] add audio device completion using
$ system_profiler SPAudioDataType -xml | xmllint --xpath '/plist/array/dict/array[2]/dict/array/dict/string[1]' - | sed -e 's|</string><string>|@|g' -e 's|<string>||g' -e 's|</string>||g' | tr '@' '\n' | sort | uniq
look at ruby bundle, menu actions > declarations > New Method for how to
dynamically build a snippet using a command
-[ ] figure out how to do auto-indenting of arrays like Python and Ruby bundles do,
and apply it to query array's and query dictionaries
in Ruby, type '[', 'return' to see the desired behavior
*/
/*
https://bunchapp.co/docs/bunch-files/frontmatter/
Simplified YAML-ish keys and values. Can contain commands and variable
assignments
*/
/*
https://bunchapp.co/docs/bunch-files/comments/
Lines that start with '# ' or '// ' are comments
You can also append ' # ' or ' // ' at the end of a line to make a comment
Block syntax is also supported for single or multi-line
*/
/*
https://bunchapp.co/docs/bunch-files/variables
Variables can be assigned in front matter, or passed into snippets, or
passed in via the URL handler
Variables can be used nearly anywhere
*/
${web site}
%{urlencoded}
${srcdir/raw}
# variables can have a default value, useful in snippets and fragments
${taskapp:OmniFocus}
# variables can also be direct assigned outside of front matter
var1 = some value
var2 = this ${var1} value
# https://bunchapp.co/docs/bunch-files/interactivity/populating-variables/
global var2 = ?"What should var2 ${var1} contain"
# variables can be assigned from a script
var2 = * myscript.applescript
var3 = $ myscript.sh ${var} "arg 2"
# https://bunchapp.co/docs/bunch-files/interactivity/multiple-choice/
var4 = ?[ First, Second, Third ] "Which ${some} one?"
var5 = ?[
First
Second
Third
] "Which one?"
var7 = ?{
Marked => <coding.snippets#Marked
Bunch => <coding.snippets#Bunch
nvUltra => <<#nvUltra
} "Whatcha Coding?"
# https://bunchapp.co/docs/bunch-files/interactivity/external-files/
var8 = ?< scripts/Menu Source.json "Pick your ${thevar} Poison"
var9 = ?<scripts/${somedir}/myfile.yaml
# markdown syntax for multi-line variables
var10 = ```
line one
all of this ${var} will be outdented
line three
```
# heredoc syntax for multi-line variables
var10 = <<DUN
line one
all of this ${var} will be outdented
line three
DUN
# variable set from contents of file, using snippet syntax
var11 = <some.snippet
var12 = <some.snippet#fragment
## embedded snippet with no fragment name
var13 = <<
# embedded snippet with a fragment name
var13 = <<# My fragment
/*
https://bunchapp.co/docs/bunch-files/apps/
Apps and files
*/
# hide all visible apps (use at top of bunch)
@@
# just a plain ol' app
Messages
# keep running when quitting bunch
%Terminal # comment
# Start a line with @ to "focus" that app (hide others)
# Focus commands should be the last item in the Bunch
# optionally add a delay in case other apps launching ahead of it
# are really slow
@Copy 'Em ~5 # comments ~5
# attempt to hide app after launching
# pipe to ask for parallel execution
#
|TextMate_
# force forground and unhide
Visual Studio Code^
/*
https://bunchapp.co/docs/bunch-files/run-on-close/
*/
# Start a line with an exclamation point to quit that app when
# starting the bunch
!Twitter
# and restart it when closing the bunch
!!Twitter
# 3 bangs quits an app when closing the bunch, even if the bunch didn't
# start the app
!!!Twitter
# open another bunch
SomeOther.bunch
# with frontmatter variables
- sequence=true
Tower
# open files by starting a line with a -
- ${srcdir}/myproj
- (pause 5) // wait 5 seconds before opening next file
- ${srcdir}/anotherproj
- (delay 5) // delay is a synonym for pause
- ${srcdir}/thirdproj
Finder
# XX is a special command for tell the app to close all windows
- XX
- ~/
-> ${srcdir}/docs # open in another tab, only works for Finder
- ~/Documents
# Default is a special app, so it gets special treatment
Default
- ~/tmp/Somefile.txt
- ~/Documents/Other file.pages // with comment at end
# you can also use spotlight here
# https://bunchapp.co/docs/bunch-files/spotlight-searches/
- #Taxes #2020 [~/Dropbox/Receipts] !25
- 'kind:"affinity photo" tag:${tagname} name:template' [~/Dropbox] !5
/*
https://bunchapp.co/docs/bunch-files/logic/
Conditional Logic
*/
if (var_one is NOT "Choice ${var} NOT 1" OR !var_one == "Choice 2")
var_two = "Project 1"
<<#Load Project
else if $var_one is "Choice 2"
if $someother AND (fred OR george)
var_two = "Project 2"
Finder
- ~/tmp/mydir
# a waiting snippet
/*
stuff here
*/
Messages
<<#Load Project
else if weekday is after friday
Brave
else if joe !*= something
Firefox
else
<<#My Fragment
$ myscript.sh ${somevar} "arg 2"
end
else
<<#Load Default
end
if self is opening
var5 = ?[
First
Second
Third
] "Which one?"
end
if self is closing
end
if Comms is opening
end
if uuid is not 43F96162-AA78-4FEF-B142-407ADC2B3154
end
if file ~/.bash_profile does not exist
iTerm2
end
if file ~/.bash_profile contains "something else"
iTerm2
end
/*
https://bunchapp.co/docs/bunch-files/interactivity/multiple-choice/
Dialogs can be used to choose which app to run
*/
othertaskmgr = 'Todoist';
?[ Omnifocus, Things, TaskPaper ] "Which Task Manager?"
?[
Omnifocus
Things
TaskPaper
] "Which Task Manager?"
# or to load a snippet
?{ Marked => <coding.snippets#Marked, Bunch => <coding.snippets#Bunch } "Whatcha Coding ${somevar}?"
?{ Marked => <coding.snippets#Marked, Bunch => <coding.snippets#Bunch }
Safari
?{
Marked => <coding.snippets#Marked
Bunch => <coding.snippets#Bunch
nvUltra => <coding.snippets#nvUltra
} "Whatcha Coding?"
Safari
# checkbox dialogs
-[x] Option 1 => <<#One
-[x] Option 2 =>
-[] Option 3 => <<#Three
---
-[ ] Option 3 => <<#Three
-[x] Omnifocus
-[] iA Writer
-[ ] Spark
# dialogs can be loaded from a file
?< scripts/Menu Source.json "Pick your ${thevar} Poison"
?<scripts/${somedir}/myfile.yaml
/*
https://bunchapp.co/docs/bunch-files/opening-web-pages/
Use a URL at the beginning of a line to open it in your
default browser. URL schemes also work.
Prefix with a browser name and a colon to open in a specific browser
*/
Safari
- https://www.duckduckgo.com
x-marked://open?file=${srcdir}/file_name.md
https://brettterpstra.com/projects
brave:https://www.kotfu.net // specify which browser to use
/*
https://bunchapp.co/docs/bunch-files/keystrokes/
keystrokes are file lines surrounded by braces
typed strings are file lines surrounded by brackets
*/
Messages
- {@N "typing with a\\!2 pause"}
- (pause 3)
- [Mom tab Hi Mom! return \\!5${longermessage/typed} return]
/*
https://bunchapp.co/docs/bunch-files/commands/
Commands are enclosed in parenthesis and can have variables
*/
(audio device_name|volume X|mute|unmute)
(hide desktop)
# pipe to request parallel execution
|(${showhide} desktop)
# ! prefix means only run this when closing the bunch
!(do not disturb ${onoff/raw} ${onoff}) // comments
# avoid reversing action when closing the bunch
%(show dock)
/*
https://bunchapp.co/docs/bunch-files/scripts/
https://bunchapp.co/docs/bunch-files/run-on-close/
https://bunchapp.co/docs/bunch-files/delay/
Lines starting with * run applescript inline or from a file
Lines starting with & run Automator Workflows
Lines starting with $ run shell scripts, which can have a (display) clause
Script lines beginning with ! are run on close
Append ~4 to delay the launch
*/
* say "Bunch launched"
* "Run This.scpt" "argument 1" "argument 2" ~5
!* say "Bunch closed"
& ~/Dropbox/MyWorkflow.workflow
!& Bunch Workflow
# Automator workflows can take variables
& WorkflowWithVariables
- variable1 = contents with = sign
# shell scripts can have a display command at the end
$ cd ~/Sites/bunch && jekyll serve (display d:1 100%x300 left,top #333 #b0d17d a:95% l:d) ~4
# and do parallel execution
# https://bunchapp.co/docs/bunch-files/scripts/shell-scripts/#order-of-execution
| Safari
| Messages
# delay after display, i.e. voice says "hello 3" after waiting 2 seconds
!$ say hello ~3 (display) ~2
# shell script with a variable as an argument and an environment variable
$ /usr/local/scripts/myscript.sh ${srcdir} arg2
- ENV_VAR=with variable interpolation ${variable1}
# embedded applescript using markdown syntax
* ```
set source_folder to choose folder with prompt "Please select directory."
-- do some cool stuff
```
# embedded applescript heredoc format
* <<EOF
set source_folder to choose folder with prompt "Please select directory."
-- do some cool stuff
EOF
# embedded shell script using markdown syntax
$ ```
#!/bin/bash
if [ $(whoami) = 'root' ]; then
say i am ${variable} groot
fi
```
# embedded shell script using heredoc syntax
$ <<EOF
#!/bin/bash
if [ $(whoami) = 'root' ]; then
say i am groot
fi
EOF
# embedded apple script using markdown syntax
* ```
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.sound"
end tell
```
# embedded apple script using heredoc syntax
* <<OMEGA
tell application "Drafts" to make new draft with properties {content:the clipboard}
OMEGA
# scripts can also be imported from snippets
$ <myscripts.sh#This Script
* <<#Embedded AppleScript
/*
https://bunchapp.co/docs/bunch-files/snippets/
*/
<Comms.snippet
<
<MySnip.snippet
<MySnip.snippet#Fragment Name
- withvariable = thevalue
<<
<<#My Fragment
<<#embedded fragment name ~5
# snippet composed of variables
!<${snipvar}#${section}
# a snippet that waits for all the other apps to load before running
<waiting.snippet#Position
# bunches as snippets
<Comms.bunch ~5
# https://bunchapp.co/docs/bunch-files/interactivity/optional-snippets/
!<Comms.bunch#Social Media ?"Fly into the ${somevar} time-shifting vortex?"
# this isn't interpreted as anything and therefore shouldn't get a scope
<<Snippet
# start marker for an embedded snippet
___
// these should all be fragment headerss; have to have 2 dashes or one
// of = > #, followed by a [
###[Fragment Name]
# [ Fragment ] #########
-------[My Fragment]-----------
-- [Fragment]
------------------------------------------[Frag]--
>>>[Some Fragment]
=[Fragment]== Add a comment, if you like
>-=# [My Fragment] #=-<