-
Notifications
You must be signed in to change notification settings - Fork 8
/
justfile
122 lines (111 loc) · 3.65 KB
/
justfile
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
# Do not prevent local external justfile recipes from being run from cwd within the repo
set fallback
justq := quote(just_executable()) + ' -f ' + quote(justfile())
test_cases := justfile_directory() / 'tests/cases'
@_default:
{{justq}} --list
# preview JUSTFILE in Vim with syntax file from this repository
[no-cd]
preview JUSTFILE='': (_preview_common 'vim' JUSTFILE)
# preview JUSTFILE in GVim with syntax file from this repository
[no-cd]
gpreview JUSTFILE='': (_preview_common 'gvim -f' JUSTFILE)
# preview JUSTFILE in Neovim with syntax file from this repository
[no-cd]
npreview JUSTFILE='': (_preview_common 'nvim' JUSTFILE)
[no-cd]
_preview_common vimcmd JUSTFILE:
{{vimcmd}} \
-c {{quote("let &runtimepath=\"" + justfile_directory() + ",\" . &runtimepath")}} \
-c {{quote("runtime ftdetect/just.vim")}} \
{{if JUSTFILE == '' { '-c "set filetype=just"' } \
else { \
"-c " + quote('edit ' + \
if path_exists(test_cases / JUSTFILE + '.just') == 'true' { \
test_cases / JUSTFILE + '.just' \
} else { JUSTFILE }) \
} }}
update-last-changed *force:
#!/bin/bash
for f in $(find * -name just.vim);do
gitrev="$(git log -n 1 --format='format:%H' -- "$f")"
if [[ {{quote(force)}} != *"$f"* ]];then
git show "$gitrev" | grep -q -P -i '^\+"\s*Last\s+Change:' && continue
fi
lastchange="$(git show -s "$gitrev" --format='%cd' --date='format:%Y %b %d')"
echo -e "$f -> Last Change: $lastchange"
sed --in-place -E -e "s/(^\"\s*Last\s+Change:\s+).+$/\\1${lastchange}/g" "$f"
done
just_boolean_settings := """
allow-duplicate-recipes
allow-duplicate-variables
dotenv-load
export
fallback
ignore-comments
positional-arguments
quiet
windows-powershell
"""
# generate an optimized Vim-style "very magic" regex snippet from a list of literal strings to match
optrx +strings:
#!/usr/bin/env python3
vparam = """{{strings}}"""
import collections, re
strings_list = vparam.split('|') if '|' in vparam else vparam.strip().split()
vimSpecialChars = tuple('~@$%^&*()+=[]{}\\|<>.?')
def vimEscape(c):
if type(c) is str and len(c) < 2:
return f'\\{c}' if c in vimSpecialChars else c
raise TypeError(f'{c!r} is not a character')
charByPrefix=dict()
for f in strings_list:
if len(f) < 1: continue
g=collections.deque(map(vimEscape, f))
p=charByPrefix
while len(g):
if g[0] not in p: p[g[0]] = dict()
p=p[g.popleft()]
p[''] = dict()
def recursive_coalesce(d, addGrouping=False):
o=''
l = collections.deque(d.keys())
# Ensure empty string is at the end
if '' in l and l[-1] != '':
l.remove('')
l.append('')
while len(l):
c = l.popleft()
o += c
if len(d[c]) > 1:
o += recursive_coalesce(d[c], True)
else:
if len(d[c]) == 1:
o += recursive_coalesce(d[c])
if len(l):
o += '|'
# Do all items in this group have a common suffix?
ss=o.split('|')
if len(ss) > 1:
commonEnd = ''
tryCommonEnd = ss[0][:]
while len(tryCommonEnd):
c=0
for j in ss:
if re.search(r'%\((?:[^)]|\\\))+$', j):
# don't compare suffix in inner group to suffix of outer group
continue
c += int(j.endswith(tryCommonEnd))
if c == len(ss):
commonEnd = tryCommonEnd
break
tryCommonEnd=tryCommonEnd[1:]
if not(commonEnd in ('', ')?')):
o = '%(' + ('|'.join(map(lambda s: s[:s.rfind(commonEnd)], ss))) + ')' + commonEnd
elif addGrouping:
o = f'%({o})'
return o.replace('|)', ')?')
print(recursive_coalesce(charByPrefix))
# run optrx on a variable from this justfile
@optrx_var var:
{{justq}} optrx "$({{justq}} --evaluate {{var}})"