Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
An enhancement of /usr/bin/firefox-bin; no new win etc.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
teika
n00b
n00b


Joined: 19 Feb 2011
Posts: 68
Location: japan

PostPosted: Tue Jan 31, 2012 1:36 am    Post subject: An enhancement of /usr/bin/firefox-bin; no new win etc. Reply with quote

The script below is a replacement /usr/bin/firefox-bin, which is included in www-client/firefox-bin.

1. When you do
$ firefox-bin *
it'll ignore *_files directories, which the original firefox-bin picks up.

2. The original firefox-bin has a defect when you open new urls from the command line, if already firefox is running. If you do
$ firefox-bin foo bar baz
then a new window is created, and these urls are shown there, while
$ firefox-bin one-url
results in a new tab. With my script, they are always opened in new tabs.

Code:
#!/bin/bash

# Based on www-client/firefox-bin-8.0

# Difference from the Gentoo original:
# Suppose firefox is already running. When you do
#   $ /usr/bin/firefox foo bar baz
# then a new window is created, and these urls are shown there, while
#   $ /usr/bin/firefox one-url
# results in a new tab.
# With this script, they're always opened in new tabs.

unset LD_PRELOAD
LD_LIBRARY_PATH="/opt/firefox/"
GTK_PATH=/usr/lib/gtk-2.0/

# Is already firefox running? Well, simple way doesn't work:
# ( -z $( pgrep -x -u $( whoami ) firefox | grep -v $to_exclude ))
# If this script is run from a symlink "firefox"
# It's probably because $() forks??

for i in $( pgrep -x -u $( whoami ) firefox ) ; do
    if [[ `cat /proc/${i}/cmdline` =~ ^/opt/firefox/firefox ]]; then
   RUNNING=t
   break
    fi
done

# filter out *_files
# If you run firefox a*, then you receive a.*_files.

args=()
for i in "$@"; do
    if [[ ( -d "$i") && ( "$i" =~ _files$ ) ]]; then
   :
    else
   args=( "${args[@]}" "$i" )
    fi
done

if [[ (( -n "$1" ) && ( "$1" =~ ^- )) || -z $RUNNING ]]; then
    exec /opt/firefox/firefox "${args[@]}"
else
    newArgs=()
    for i in "${args[@]}"; do
   if [[ ( -e "$i" ) || ( "$i" =~ ^file:// ) || ( "$i" =~ ^http ) ]]; then
       newArgs=( "${newArgs[@]}" -new-tab "$i" )
   else
       newArgs=( "${newArgs[@]}" "$i" )
   fi
    done
    /opt/firefox/firefox "${newArgs[@]}" &
fi


I think it can be improved; I'm not good at bash.

/usr/bin/firefox-bin is created by the ebuild, not distributed by mozilla.com. If this script is refined enough, then I may send it to Gentoo bugzilla. Enjoy.
_________________
Easy Shift / Ctrl / AltGr ... hack; save your pinkies, type without drudge: topic 865313


Last edited by teika on Thu Mar 22, 2012 10:46 pm; edited 2 times in total
Back to top
View user's profile Send private message
teika
n00b
n00b


Joined: 19 Feb 2011
Posts: 68
Location: japan

PostPosted: Thu Mar 01, 2012 11:12 am    Post subject: Reply with quote

[Now obsolete]
The above script doesn't work any more. It seems that it can be fixed by prefixing each url with "-new-tab". The code which mostly works is easy to write, but wait a bit for a fairly good one. Or someone can contribute one, I'll be grateful. =)
Back to top
View user's profile Send private message
teika
n00b
n00b


Joined: 19 Feb 2011
Posts: 68
Location: japan

PostPosted: Thu Mar 22, 2012 10:56 pm    Post subject: Reply with quote

Updated. Now it seems to work again.

Without any comments, it'll never be sent to Gentoo bugzilla. I can't judge the quality of my own code. (If it's to be merged to the official ebuild, this feature should be optional, but it's a minor issue.)

Regards.
_________________
Easy Shift / Ctrl / AltGr ... hack; save your pinkies, type without drudge: topic 865313
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum