]> piware.de Git - bin.git/blob - shellpresent
shellpresent: return to $ prompt after command finished, looks more natural
[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 echo -en "\e[31m\$\e[30m "
17
18 while read line; do
19     # paragraph clears screen
20     if [ -z "$line" ]; then
21         clear
22         echo -en "\e[31m\$\e[30m "
23         continue
24     fi
25
26     # comment
27     if [ "${line:0:1}" = "#" ]; then
28         if [ -n "${line:1}" ]; then
29             echo -e "\r\e[32m$line\e[30m"
30             echo -en "\e[31m\$\e[30m "
31         fi
32         continue
33     fi
34
35     # execute command
36     echo -n "$line"
37     read < /dev/tty
38     eval "$line"
39     echo -en "\n\e[31m\$\e[30m "
40     read -s < /dev/tty
41 done < "$1"