> I have a shell script called netscape (for historical reasons) which
> does (essentially)
>       firefox -remote "openurl($1,new-window)" &

On the mailing list of my window manager (dwm), Karl suggested to write
a more complex script. I have simplified it as in the attachment, see the 
archives of
[EMAIL PROTECTED] for the original.

In my version, it checks that the selection is an URL or a path and fails
otherwise (with meaningful error messages, so that it can be called from
an interactive shell), then it opens the URL in a firefox tab is firefox
is running and launches a new firefox otherwise.

I am not a real scripter, so sorry for the casual indentation & C. Any
correction and further suggestion more than welcome.
For the x selection, I have settled on sselp, which is lighter than xsel
and strip any possible additional chars.

http://www.suckless.org/wiki/tools/xlib

Thanks for the great suggestion
Giorgio
#! /bin/sh
SSELPSOME=false
for TARGET in $(sselp | tr ' !|<>,' '\n'); do
      # Choose anything that looks like it could be a url (contains
      # a '.' with at least one char on each side) or path (starts
      # with a '/' - only absolute paths are reasonable when opening
      # from clipboard - there is no sensible working dir)
      if [ \
        "${TARGET#*?.?}"  != "$TARGET" -o \
        "${TARGET#/*?/?}" != "$TARGET"    \
        ]; then
         # Don't open anything with an '@' in it, since it's probably an email 
address!
         if [ "[EMAIL PROTECTED]" = "$TARGET" ]; then
            # Open the URL in a new firefox tab if firefox is running, launch 
new firefox otherwise
            if [ $(ps aux | grep firefox-bin | wc -l) -gt 1 ]; then
                firefox3 -new-tab "$TARGET"
            else
                firefox3 "$TARGET"
            fi
         else
            echo Probably an email address: "$TARGET"
         fi
      else
         echo Not an URL: "$TARGET"
      fi
      SSELPSOME=true
done
# if nothing in the clipboard
if [ $SSELPSOME != true ]; then
      echo No selection
fi
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Materm-usage mailing list
Materm-usage@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/materm-usage
Mrxvt home page: http://materm.sourceforge.net

Reply via email to