-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixindent.tiny
49 lines (41 loc) · 1.2 KB
/
fixindent.tiny
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
###############################################################
#
# Tiny utility script to fix indentation rounding to the
# nearest 4 spaces.
#
###############################################################
import 'utils'
import 'IO'
options = Utils.GetOpts('fixindent', args, {
filename: null
output: null
})
if (not(options.filename)) {
error "FixIndent: you must provide the 'filename' option naming the file to process."
error (" Available options: " + keys(options))
return null
}
options.filename |> IO.testpath |> not then {
error("FixIndent: the specified file '{0}' does not exist.", options.filename)
return null
}
outfile = options.output ?? options.filename + '.new'
alert("Processing input file '{0}' to output file '{1}'", options.filename, outfile)
time {
options.filename
|> IO.readalllines
|> map {
line = it
line ~ r/^(\s*)/ then {
len = matches[1] |> length
if (len % 4 == 0) {
line
}
else {
" " * (len + 4 - len % 4) + (line -~ r/^\s*/)
}
}
}
|> writefile(outfile, [<System.Text.Encoding>].ASCII)
return null
}