public
Description: Run programs in the Emacs buffer holding their source, seeing their output inline, interactively.
Homepage: http://wry.me/project/halp
Clone URL: git://github.com/darius/halp.git
halp / sh-halp.sh
100755 21 lines (16 sloc) 0.603 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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
 
grep -v '^| ' >${work}/input
awk '/^[$]/ { print NR >"'${work}/line_numbers'";
print "echo -n SEP;" substr($0, 2); }' ${work}/input |
  sh | sed 's/^SEP/| /' |
  awk '
{ getline linenumber <"'${work}/line_numbers'";
print linenumber "a \\";
print $0; }' >${work}/edits
 
sed -f ${work}/edits <${work}/input
 
rm -r ${work}