-
Notifications
You must be signed in to change notification settings - Fork 4
/
ghci-halp.sh
executable file
·30 lines (24 loc) · 1016 Bytes
/
ghci-halp.sh
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
#!/usr/bin/env bash
# Copyright 2006 by Darius Bacon and Brandon Moore
# Distributed under the terms of the MIT X License, found at
# http://www.opensource.org/licenses/mit-license.php
work=`mktemp -d /tmp/halp.XXXXXXXXXX`
touch ${work}/line_numbers
sed 's/module.*?where/module Main where/' | grep -v '^| ' >${work}/Main.lhs
echo '
> aouhtnuoeahn = 0 -- Ensure file has *some* code.' >>${work}/Main.lhs
awk '/^[)]/ { print NR >"'${work}/line_numbers'";
print substr($0, 2); }' ${work}/Main.lhs |
ghci ${work}/Main.lhs 2>&1 |
awk '
NR <= 4 { next; }
/Leaving GHCi[.]/ { next; }
{ sub(/[*]Main> /, "| "); print; } ' |
awk '
{ getline linenumber <"'${work}/line_numbers'";
print linenumber "a \\";
print $0; }' >${work}/edits
sed -f ${work}/edits <${work}/Main.lhs |
# XXX This assumes the original sourcefile ended in a newline character:
awk '{ line[NR] = $0; }; END { for (i = 1; i <= NR-3; ++i) print line[i]; }'
rm -r ${work}