]> piware.de Git - bin.git/blob - shellpresent
add shellpresent
[bin.git] / shellpresent
1 #!/bin/bash
2 #
3 # Present a list of shell commands by single-stepping and echoing commands.
4 # Note that this only works well for self-contained single lines, no multi-line
5 # loops etc.
6 #
7 # (c) 2009 Martin Pitt <martin@piware.de>
8 # License: Public Domain
9
10 [ -e "$1" ] || {
11     echo "Usage: $0 <shell script>" >&2
12     exit 1
13 }
14
15 clear
16
17 while read line; do
18     # paragraph clears screen
19     if [ -z "$line" ]; then
20         clear
21         continue
22     fi
23
24     # comment
25     if [ "${line:0:1}" = "#" ]; then
26         if [ -n "${line:1}" ]; then
27             echo -e "\e[32m$line\e[30m"
28         fi
29         continue
30     fi
31
32     # execute command
33     echo -en "\e[31m\$\e[30m $line"
34     read < /dev/tty
35     eval "$line"
36     read < /dev/tty
37 done < "$1"