On Thu, Mar 18, 2004 at 09:30:16PM -0800, Bryan Murdock wrote:
> You need to have firefox in your path if you want to be able to type
> firefox all by itself on the command line (maybe you've already done
> this, but you didn't tell us enough for me to know better).  If you
> installed it in /usr/loca/bin/firefox then edit your ~/.bashrc and put a
> line at the end like this:
> 
> export PATH=$PATH:/usr/local/bin/firefox
> 
> Then source it by typing
> 
> . ~/.bashrc
> 
> Then no matter what directory you are in you can type firefox and it
> will start.  Passing it the url should just work too.
> 

Ok, here's something dang cool.  If you don't mind doing a bit of
editing, this file, when you drop it in your /usr/local/bin you'll be
able to tell firefox to launch the site in a new tab/window if firefox
is already running.  I personally love this feature.  The script is
attached at the end after being cleaned up a bit.

It should be fairly straight foward, just change the two varibles. (the
part in quotes that says "tab" and "/usr/lib/MozillaFirefox" to the
correct things).

Enjoy!
-- 
Scott Paul Robertson
http://students.cs.byu.edu/~spr/
GnuPG FingerPrint: 09ab 64b5 edc0 903e 93ce edb9 3bcc f8fb dc5d 7601
#!/bin/bash
#
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /home/cvsroot/gentoo-x86/net-www/mozilla-firefox/files/firefox,v 1.4 
2004/02/16 05:47:56 brad Exp $

# Set MOZILLA_NEWTYPE to "window" in your environment if you prefer
# new Firefox windows instead of new tabs
newtype=${MOZILLA_NEWTYPE:-"tab"}

# Point this to your Firefox installation if not using the default
export MOZILLA_FIVE_HOME="/usr/lib/MozillaFirefox"
ffpath=${MOZILLA_FIVE_HOME}

# Sanity check
if [[ -z $DISPLAY ]]; then
  echo "DISPLAY is unset!" >&2
  exit 1
fi

# Validate the args and extract the urls
args=()
urls=()
while [[ $# -ne 0 ]] ; do
  if [[ $1 == -* ]] ; then
    case "${1#-}" in
      height|width|CreateProfile|P|UILocale|contentLocale|remote|edit|chrome)
        args=("[EMAIL PROTECTED]" "$1" "$2")
        shift 2 ;;
      *)
        args=("[EMAIL PROTECTED]" "$1")
        shift 1 ;;
    esac
  else
    urls=("[EMAIL PROTECTED]" $1)
    shift
  fi
done

# Try to start in an existing session; check all screens
declare -a screens=(
  $(/usr/X11R6/bin/xdpyinfo | awk '
    /^name of display:/ { 
      disp = substr($NF, 0, index($NF, ".")-1) 
    }
    /^number of screens:/ {
      for (i = 0; i < $NF; i++) printf("%s.%d\n", disp, i)
    }')
  )

# Attempt to fix bug 39797 by making sure MozillaFirefox is running
# on the DISPLAY prior to calling mozilla-xremote-client.  The
# problem here is that mozilla-xremote-client will return a zero
# exit status if it contacts a Thunderbird-0.3 instance, even though
# Thunderbird can't handle the openURL request.  :-(
#
# Note: This seems to be fixed with Thunderbird-0.4, which rejects the
# openURL request appropriately.
declare -a candidates=()
for s in $DISPLAY "[EMAIL PROTECTED]"; do 
  if DISPLAY=${s} xwininfo -root -tree | grep -q 'firefox-bin'; then
    candidates=("[EMAIL PROTECTED]" ${s})
  fi
done

# Make sure we'll get at least an empty window/tab
[[ [EMAIL PROTECTED] == 0 ]] && urls=('')

# Handle multiple URLs by looping over the xremote call
for u in "[EMAIL PROTECTED]"; do

  # prepend http:// if needed
  [[ $u == ? && $u != *:* ]] && u=http://$u

  # try mozila-xremote-client on each candidate screen
  if [[ [EMAIL PROTECTED] > 0 ]]; then
    for s in "[EMAIL PROTECTED]"; do 
      DISPLAY=${s} \
        ${ffpath}/mozilla-xremote-client "openURL($u, new-$newtype)" \
        && break
    done
    retval=$?
  else
    # simulate mozilla-xremote-client's response when it can't find an instance
    retval=2
  fi

  # 2 = No running windows found, so start a new instance
  # 3 = Thunderbird is running, but doesn't handle openURL command
  #     (or it might be an unresponsive Firefox)
  if [[ $retval -eq 2 || $retval -eq 3 ]] ; then

    # Handle case of multiple URLs
    if [[ [EMAIL PROTECTED] > 1 ]]; then
      ${ffpath}/firefox "[EMAIL PROTECTED]" "$u" &
      if [[ -x /usr/bin/xtoolwait ]]; then
        xtoolwait sleep 10
      else
        sleep 10   # totally arbitrary! :-(
      fi
      candidates=$DISPLAY
      continue
    fi

    # Handle case of single URL
    ${ffpath}/firefox "[EMAIL PROTECTED]" "$u" &
    break

  elif [[ $retval -eq 1 ]]; then
    echo "Unable to connect to X server" >&2
  elif [[ $retval -ne 0 ]]; then
    echo "Unknown error $retval from mozilla-xremote-client" >&2
  fi

done

# Will only wait here if firefox was started by this script
if ! wait; then
  retval=$?
  echo "firefox exited with non-zero status ($?)" >&2
fi

exit $retval

# vim:expandtab sw=2:

Attachment: pgp00000.pgp
Description: PGP signature

_______________________________________________
newbies mailing list
[EMAIL PROTECTED]
http://phantom.byu.edu/cgi-bin/mailman/listinfo/newbies

Reply via email to