--- moz-0.2.2a Sat Nov 30 06:04:56 2002 +++ moz-0.2.2b Sat Nov 30 06:04:58 2002 @@ -1,7 +1,7 @@ #!/bin/sh echo # ---------------------------------------------------------------------------- -echo -e "\033[1mmoz 0.2.2a -- Starts a new Mozilla process or accesses a URI in a running one\033[m" +echo -e "\033[1mmoz 0.2.2b -- A Mozilla process manager\033[m" echo "Copyright (c) 2002 Thomas Lahn " # # This program is free software; you can redistribute it and/or modify @@ -24,18 +24,16 @@ # ChangeLog # ========== # -# 0.2.2 (2002-11-29) +# 0.2.2 (future) # ------------------ # * Accessing the URI in a new browser tab (Mozilla 1.0.1, 1.1 and beyond). # * Mixing of new-window, new-tab and new-process options. +# * With -k, first try SIGTERM(15) and if (and only if) this has no effect, +# send SIGKILL(9) # * Cosmetics: # - Added status messages -# - Bold-formatted title -# -# 0.2.1 (2002-11-28) -# ------------------- -# * More than one URI -# * Termination/killing of a running Mozilla process +# - Bold-formatted title with changed tagline +# - Updated and reformatted help screen # # See the ChangeLog text file for further information. # @@ -43,36 +41,44 @@ function help { echo - echo "Usage: `basename $0` [ ( --term | --kill | -? ) ]" - echo " [ ( -w | -t ) ] [URI] [...] [ ( -w | -t ) ] [...]" + echo "Usage: `basename $0` [ ( -? | --term | --kill ) ]" + echo " [ ( -w | -t | - ) ] [URI] [...] [ ( -w | -t | - ) ] [...]" echo + echo "-?, --help Show this help screen." # version 0.2.3 proposal # echo " --block Block the shell for the \`mozilla' process, i.e. prevent" # echo " following commands to be executed until Mozilla is quit." - echo " --term Terminate all Mozilla processes (first). Note that the" - echo " -t option now refers to the creation of a new browser tab" - echo " for POSIX conformance. See below." - echo "-k, --kill Kill all Mozilla processes (first). Note that -k (but not" - echo " --kill) will become obsolete in future versions for" - echo " POSIX conformance." - echo "-n, --new Same as -w. This may become obsolete in future versions." + echo " --term Terminate all \`mozilla-bin' processes (first), sending each of" + echo " them a SIGTERM(15) signal. Need not to work as a process may" + echo " refuse to terminate (see -k). Note that the -t option, which" + echo " was previously short for --term, now (for POSIX conformance)" + echo " refers to the creation of a new browser tab (see below)." + echo "-k, --kill Kill all \`mozilla-bin' processes (first). Tries first to" + echo " send each of the processes a SIGTERM(15) signal to end" + echo " them politely, and if (and only if) this does not work," + echo " send them the kinda rude SIGKILL(9) signal." + echo " Note that -k (but not --kill) may become obsolete in" + echo " future versions for POSIX conformance." + echo "-n, --new Same as -w. For backward compatibility only, this may become" + echo " obsolete in future versions." echo "-w, --win Show the resource(s) specified by URI in a new browser window." echo " If not provided, the current window/tab content will be" - echo " replaced. Resources with \`mailto:' URIs will create a" - echo " new e-mail compose window anyway." + echo " replaced. Resources with \`mailto:' URIs will create a new" + echo " e-mail compose window anyway." echo "-t, --tab Show the resource(s) specified by URI in a new browser tab." - echo " Works with Mozilla 1.0.1, 1.1 and beyond." - echo " If not provided, the current window/tab content will be" - echo " replaced. Resources with \`mailto:' URIs will create a" - echo " new e-mail 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 " specified otherwise with -t or a \`mailto:' URI)." - echo " Use \`-' NOT to (re)start Mozilla or access another URI." - echo " Useful with --term or --kill." + echo " Works with Mozilla 1.0.1, 1.1 and beyond. If not provided," + echo " the current window/tab content will be replaced. Resources" + echo " with \`mailto:' URIs will create a new e-mail compose window" + echo " anyway." + echo "URI The URI(s) of the resource(s) to display. If not provided and" + echo " no further options are given this help screen is displayed." + echo " Two or more URIs are separated by spaces, while the second" + echo " and following resources are displayed in a new browser window" + echo " (if not specified otherwise with -t or a \`mailto:' URI.)" + echo " Use \`-' to (re)start Mozilla with a blank page (new process)" + echo " or show a window that allows you to select what to do (Mozilla" + echo " 1.1 and beyond). This disables any previous -w or -t options" + echo " and is especially useful in conjunction with --term or -k." echo } @@ -96,6 +102,8 @@ } function KillMoz { + local result=0 + if [ -n "`ps -A | grep mozilla-bin`" ]; then echo -n "Sending all Mozilla processes the " case "$1" in @@ -104,7 +112,8 @@ esac echo -n " signal... " killall $1 mozilla-bin 2> /dev/null - if [ $? -ne 0 ]; then + result=$? + if [ $result -ne 0 ]; then msg_failed echo else @@ -113,6 +122,8 @@ else echo -e "No Mozilla process is running that could be terminated or killed." fi + + return $(( $result )) } echo "Protected under the terms of the GNU General Public License (GPL)." @@ -134,7 +145,8 @@ if [ "$1" = "--term" ] || [ "$1" = "--kill" ] || [ "$1" = "-k" ]; then kill=1 if [ "$1" = "--kill" ] || [ "$1" = "-k" ]; then sig=-9; fi - KillMoz $sig + KillMoz + if [ $? -ne 0 ] && [ $sig -eq -9 ]; then KillMoz $sig; fi shift test -z "$1" && echo && exit 0 fi @@ -163,8 +175,8 @@ new_tab=0 if [ "$1" = "-t" ] || [ "$1" = "--tab" ]; then new_tab=1; shift; fi - # check for disable new-* - test "$1" = "-" && shift && test -z "$1" && echo && exit 0 + # check for disabling new-* + test "$1" = "-" && shift # check if the current user has Mozilla already run chk=`ps -u $(whoami) | grep mozilla-bin`