Created
August 31, 2011 21:49
-
-
Save bluegraybox/1184819 to your computer and use it in GitHub Desktop.
Framework for shell script wizard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Interactive wizard to walk the user through a process. | |
# Tracks steps completed; allows user to exit at any point and pick back up there. | |
function step1 () { | |
read -p "step 1 ok, $1? " ok | |
} | |
function step2 () { | |
read -p "step 2 ok, $1? " ok | |
} | |
function step3 () { | |
read -p "step 3 ok, $1? " ok | |
} | |
function step4 () { | |
read -p "step 4 ok, $1? " ok | |
} | |
function step5 () { | |
read -p "step 5 ok, $1? " ok | |
} | |
function step6 () { | |
read -p "step 6 ok, $1? " ok | |
} | |
function step7 () { | |
read -p "step 7 ok, $1? " ok | |
} | |
base=${0%.sh} | |
if [ ! -e $base.cfg ] ; then | |
# initialize the file with all the steps | |
echo -e "step1\nstep2\nstep3\nstep4\nstep5\nstep6\nstep7" > $base.cfg | |
fi | |
for x in `grep -v ^# $base.cfg` ; do | |
$x foo | |
# mark the step complete with a hash. | |
sed -i "s/$x/# $x/;" $base.cfg | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example session:
$ ./wizard.sh
step 1 ok, foo?
step 2 ok, foo?
step 3 ok, foo?
[ctrl-c]
$ ./wizard.sh
step 3 ok, foo?
step 4 ok, foo?
step 5 ok, foo?
step 6 ok, foo?
[ctrl-c]
$ ./wizard.sh
step 6 ok, foo?
step 7 ok, foo?
[ctrl-c]
$ ./wizard.sh
$