Re: [elinks-users] set elinks to default browser in X-Windows

2011-05-24 Thread Fabienne Ducroquet
On Tue, May 17, 2011 at 11:11:58AM -0400, Robert Jim Fulner wrote:
 Your script is a little beyond my understanding. Would you mind taking 
 some time to explain what's actually going on here?

Sorry for the delay; I wrote line by line explanations (maybe more than 
you wished), and since this allowed me to think again about it I wrote 
an improved version of the script.

  #!/bin/sh

This must be the first line (and there must be no space before #!) and means 
that when you execute the script (the file must be executable), the content 
will 
be interpreted by the shell /bin/sh (this is linked to dash for me).

  if elinks -remote ping\(\) 2/dev/null; then

elinks -remote ping\(\) returns true if ELinks is running. It's necessary to 
escape the parentheses with \ (writing ping() with double quotes would also 
work) otherwise the shell interprets ping() as the start of a function 
definition.
2/dev/null means that the error output of this command is discarded, so 
that if ELinks is not running you won't see the error message it 
displays:
ELinks: No running ELinks found.

  exec elinks -remote ${1:-about:blank}

If an ELinks instance was found, run the command
elinks -remote ${1:-about:blank}
${1:-about:blank} means:
- $1, i.e. the first parameter of the script if there was one;
- about:blank by default, you can replace it with whatever URL you like.
So if a URL was passed as a parameter it is opened in a new tab, 
otherwise a new tab with the URL about:blank is opened ('elinks -remote' alone 
returns an error).

  elif [ -n $DISPLAY ]; then

[ -n $DISPLAY ] is the same as test -n $DISPLAY and returns true if the 
DISPLAY environment variable is set, which means that an X server is available.

  exec roxterm -p ELinks -e elinks $1

In that case, execute
roxterm -p ELinks -e elinks $1
Which means launch a new roxterm window with the profile ELinks, and 
execute the command 'elinks $1' in this window.
As above $1 is the first parameter given to the script, I didn't set 
a default parameter in case $1 is empty because 'elinks' with no 
parameter doesn't return an error.
   You should replace roxterm -p ELinks with the terminal emulator and 
options you want to use. The option -e is standard for all terminal 
emulators and allows to run a command in the new terminal, but with some 
terminal emulators it's necessary to write
... -e elinks $1
because they interpret only the argument of the option as the command to 
run, while most emulators interpret everything until the end of the line 
as the command.

  else
  elinks $1
  fi

If neither ELinks nor X is running we are in a Linux console, just run elinks 
with the given URL. If you don't care about this case you can remove it 
and replace elif ... then with else.

  exit 0

Return 0 (no error) when finishing the script, but I think this line 
should be removed, because it hides the error code possibly returned by 
one of the previous commands (and anyway with the exec's this line is 
not even read).

The exec at the beginning of the lines mean that the command following 
replaces the shell. Actually I don't see any difference when I remove 
them, but since the aim of the script is to launch another program 
I think it's better to keep them (and add one in the third case).

A thing that is missing from the script is an  at the end of the line with 
the terminal emulator, in order to run the command in the background (this 
changes nothing for roxterm and some others, but is useful with e.g. xterm if 
you run the script from a terminal).

It's also possible to use variables to set your preferences, so here is 
an improved version, with xterm as a terminal emulator:

#!/bin/sh

DEFAULT_URL=about:blank
TERMINAL=xterm

if elinks -remote ping\(\) 2/dev/null; then
exec elinks -remote ${1:-$DEFAULT_URL}
elif [ -n $DISPLAY ]; then
exec $TERMINAL -e elinks $1 
# If you get an error or if the URL is ignored with your 
# TERMINAL setting, comment the line above and use the 
following 
# instead:
#exec $TERMINAL -e elinks $1 
else
exec elinks $1
fi

Or more simply, if you don't care about the no X display case:

#!/bin/sh

DEFAULT_URL=about:blank
TERMINAL=xterm

if elinks -remote ping\(\) 2/dev/null; then
exec elinks -remote ${1:-$DEFAULT_URL}
else
exec $TERMINAL -e elinks $1 
# If you get an error or if the URL is ignored with your 
# TERMINAL setting, comment the line above and use the 
following 
# instead:
#exec $TERMINAL -e elinks $1 
fi


When I wrote the first version of this script a few years ago I intended 
to send a patch with something like that to include it in the 
documentation of ELinks (there is already 

Re: [elinks-users] set elinks to default browser in X-Windows

2011-05-17 Thread Robert Jim Fulner
Fabienne,

Thanks a lot.

Your script is a little beyond my understanding. Would you mind taking 
some time to explain what's actually going on here?

==
Jim Fulner
3059 Cumberland Rd
Berkley, MI 48072
248-971-0259

Sent with Iceape Mail

elinks-users-requ...@linuxfromscratch.org wrote:

 exec elinks -remote {URL:+$URL}
   ^
 A $ is missing here.

 I've written a wrapper script that opens the link in a new tab if ELinks
 is running, and otherwise launches ELinks in a new terminal window (here
 roxterm with a specific profile for ELinks) if X is running, or in the
 console if not.

   #!/bin/sh

   if elinks -remote ping\(\) 2/dev/null; then
   exec elinks -remote ${1:-about:blank}
   elif [ -n $DISPLAY ]; then
   exec roxterm -p ELinks -e elinks $1
   else
   elinks $1
   fi

   exit 0

 I've put this in the file ~/bin/relinks and set the $BROWSER environment
 variable to relinks (export BROWSER=relinks in ~/.bash_profile or
 ~/.profile), so sensible-browser uses relinks to open URLs.

 Fabienne



 --

 ___
 elinks-users mailing list
 elinks-users@linuxfromscratch.org
 http://linuxfromscratch.org/mailman/listinfo/elinks-users


 End of elinks-users Digest, Vol 743, Issue 1
 
___
elinks-users mailing list
elinks-users@linuxfromscratch.org
http://linuxfromscratch.org/mailman/listinfo/elinks-users


Re: [elinks-users] set elinks to default browser in X-Windows

2011-05-16 Thread Fabienne Ducroquet
Le Sun, 15 May 2011 22:09:32 -0400, Robert Jim Fulner
ful...@gmail.com a écrit :
exec elinks -remote {URL:+$URL}
 ^
A $ is missing here.

I've written a wrapper script that opens the link in a new tab if ELinks 
is running, and otherwise launches ELinks in a new terminal window (here 
roxterm with a specific profile for ELinks) if X is running, or in the 
console if not.

#!/bin/sh

if elinks -remote ping\(\) 2/dev/null; then
exec elinks -remote ${1:-about:blank}
elif [ -n $DISPLAY ]; then
exec roxterm -p ELinks -e elinks $1
else
elinks $1
fi

exit 0

I've put this in the file ~/bin/relinks and set the $BROWSER environment 
variable to relinks (export BROWSER=relinks in ~/.bash_profile or 
~/.profile), so sensible-browser uses relinks to open URLs.

Fabienne

___
elinks-users mailing list
elinks-users@linuxfromscratch.org
http://linuxfromscratch.org/mailman/listinfo/elinks-users