--- moz-0.2.0 Thu Nov 28 03:03:32 2002 +++ moz-0.2.1 Thu Nov 28 03:18:14 2002 @@ -1,7 +1,7 @@ #!/bin/sh echo # ---------------------------------------------------------------------------- -echo "moz 0.2 -- Starts a new Mozilla process or accesses a URI in a running one" +echo "moz 0.2.1 -- Starts a new Mozilla process or accesses a URI in a running one" echo "Copyright (c) 2002 Thomas Lahn " # # This program is free software; you can redistribute it and/or modify @@ -19,18 +19,78 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # This is work in progress. Feel free to report any bugs. +# +# ChangeLog +# ========== +# +# 0.2.1 (2002-11-28) +# ------------------- +# * Allow more than one URI +# * Allow termination/killing of a running Mozilla process +# +# 0.2.0 (2002-11-04) +# ------------------- +# * First public release (GPL) +# # ---------------------------------------------------------------------------- function help { - echo "Usage: moz [-n | -?] [URI]" + echo "Usage: moz [ ( -t | -k ) ] [ ( -n | -? ) ] [URI] [...]" echo - echo "--new, -n Use this option to show the resource specified by URI" - echo " in a new browser window. If not provided, the current" - echo " resource will be replaced. Resources with mailto: URIs" - echo " will create a new e-mail compose window anyway." - echo "--help, -? Show this help screen." - echo "URI The URI of the resource to access. If not provided," - echo " the configured home page is accessed." +# version 0.2.2 proposal +# echo "-b, --block Block the shell for the \`mozilla' process, i.e. prevent" +# echo " following commands to be executed until Mozilla is quit." + echo "-t, --term Terminate all Mozilla processes (first)." + echo "-k, --kill Kill all Mozilla processes (first)." + echo "-n, --new Show the resource specified by URI in a new browser window." + echo " If not provided, the current resource will be replaced." + echo " Resources with \`mailto:' URIs will create a new e-mail" + echo " compose window anyway." + echo "-?, --help Show this help screen." + echo "URI The URI(s) of the resource(s) to display. If not provided," + echo " the configured home page is displayed. Two or more URIs" + echo " are separated by spaces, while the second and following" + echo " resources are displayed in a new browser window (if not" + echo " a \`mailto:' URI)." +} + +rc_done="\033[1mdone\033[m" +rc_failed="\033[1m\033[31mfailed\033[m" + +function msg_done { + if [ -n "$rc_done" ]; then + echo -e $rc_done + else + echo "done" + fi +} + +function msg_failed { + if [ -n "$rc_failed" ]; then + echo -e $rc_failed + else + echo "failed" + fi +} + +function KillMoz { + if [ -n "`ps -A | grep mozilla-bin`" ]; then + echo -n "sending all Mozilla processes the " + case "$1" in + "-9") echo -n "KILL";; + *) echo -n "TERM";; + esac + echo -n " signal... " + killall $1 mozilla-bin 2> /dev/null + if [ $? -ne 0 ]; then + msg_failed + echo + else + msg_done + fi + else + echo -e "No Mozilla process is running that could be terminated or killed.\n" + fi } echo "Protected under the terms of the GNU General Public License (GPL)." @@ -38,51 +98,73 @@ echo "This is work in progress. Feel free to report any bugs." echo -if [ "$1" = "--help" ] || [ "$1" = "-?" ]; then +if [ "$1" = "-?" ] || [ "$1" = "--help" ]; then help else + # check for term/kill + if [ "$1" = "--term" ] || [ "$1" = "-t" ] || [ "$1" = "--kill" ] || [ "$1" = "-k" ]; then + if [ "$1" = "--kill" ] || [ "$1" = "-k" ]; then sig=-9; fi + KillMoz $sig + shift + test -z "$*" && exit 0 + fi + + # check for Mozilla chk=`which mozilla 2> /dev/null` if [ -z "$chk" ]; then echo "moz Error: The \`mozilla' executable is required for this script." echo exit 255 fi + + # check for block mode + # if [ "$1" = "-b" ] || [ "$1" = "--block" ]; then block=1; shift; fi + # check for new-window new_win=0 - if [ "$1" = "--new" ] || [ "$1" = "-n" ]; then new_win=1; shift; fi - # check if the current user has Mozilla already run - chk=`ps -u $(whoami) | grep mozilla-bin` - if [ -z "$chk" ]; then - echo -n "Starting a new Mozilla process" - test -n "$1" && echo -n " with URI '$1'" - echo "..." - mozilla "$1" & - else - # check what kind of URI was given - cmd="openURL($1" - test $new_win -eq 1 && cmd=$cmd", new-window" - cmd=$cmd")" - # checking for grep - chk=`which grep 2> /dev/null` + if [ "$1" = "-n" ] || [ "$1" = "--new" ]; then new_win=1; shift; fi + + while [ -n "$1" ]; do + # check if the current user has Mozilla already run + chk=`ps -u $(whoami) | grep mozilla-bin` if [ -z "$chk" ]; then - echo "moz Error: \`grep' not found. Cannot check for mailto: URI." + echo -n "Starting a new Mozilla process" + test -n "$1" && echo -n " with URI '$1'" + echo "..." + #if [ $block -eq 1 ]; then + # mozilla "$1" + #else + mozilla "$1" & + #fi else - if [ -n "`echo "$1" | grep "^mailto:"`" ]; then - address="$1" - # checking for sed - chk=`which sed 2> /dev/null` - if [ -z "$chk" ]; then - echo "moz Error: \`sed' not found. Cannot handle mailto: URI properly." - else - address=`echo "$address" | sed "s/^mailto://"` + # check what kind of URI was given + cmd="openURL($1" + test $new_win -eq 1 && cmd=$cmd", new-window" + cmd=$cmd")" + # checking for grep + chk=`which grep 2> /dev/null` + if [ -z "$chk" ]; then + echo "moz Error: \`grep' not found. Cannot check for mailto: URI." + else + if [ -n "`echo "$1" | grep "^mailto:"`" ]; then + address="$1" + # checking for sed + chk=`which sed 2> /dev/null` + if [ -z "$chk" ]; then + echo "moz Error: \`sed' not found. Cannot handle mailto: URI properly." + else + address=`echo "$address" | sed "s/^mailto://"` + fi + cmd="mailto($address)" fi - cmd="mailto($address)" fi + echo -n "Accessing URI '$1'" + test $new_win -eq 1 -a $mailto=0 && echo -n " in a new browser window" + echo "..." + mozilla -remote "$cmd" & fi - echo -n "Accessing URI '$1'" - test $new_win -eq 1 -a $mailto=0 && echo -n " in a new browser window" - echo "..." - mozilla -remote "$cmd" & - fi + shift + new_win=1 + done fi -echo \ No newline at end of file +echo