# script-functions -- scripting functions for bash. # # (c) 2006 Stephen Jungels. You may use and distribute these # functions freely provided that you include this copyright # notice and disclaimer. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. function macro() { mkdir -p ~/bin if ! test -e ~/bin/macro.awk then cat > ~/bin/macro.awk < file printf "\n" > file } if (\$2 \$3 == "macrorecord") { record = 1 close (file) print "#!/bin/bash" > file } } EOT fi case "$1" in save) if test "-$2-" = "--" then fn=macrofile else fn="$2" fi history | awk -v file="$fn" -f ~/bin/macro.awk chmod +x "$fn" echo Macro saved in $fn. ;; record) echo Recording macro. Type \"macro save\" and a file name to save. ;; *) echo Use \"macro record\" to begin recording commands. esac } function scriptify() { start=0 end=0 sf=scriptfile # arguments are free form while test $# -gt 0 do # this is a numericity test test 2>/dev/null "$1" -gt 0 if test $? -eq 2 then sf="$1" else if test $start = 0 then start=$1 else if test $end = 0 then end=$1 else echo Usage is \"scriptify [start] [end] [file]\". Arguments optional and in any order. return fi fi fi shift done if test $start = 0 then start=`history 2 | awk '{if (FNR==1) print $1}'` fi if test $end = 0 then end=$start fi if test $start -gt $end then temp=$start start=$end end=$temp fi mkdir -p ~/bin cat > ~/bin/scriptify.awk < "$sf" -f ~/bin/scriptify.awk chmod +x "$sf" echo Script saved to $sf }