Trucs:Utiliser Mozilla en local

De Lea Linux
Aller à la navigation Aller à la recherche
J-Michel Fayard<jean-michel.fayard@moufrei.de>

Supposons que vous vouliez consulter la documentation de mplayer. En gourou d'Unix, vous faîtes :

cd /usr/share/doc/mplayer-*/French/

L'aide se trouve être au format html. Pour l'afficher, vous tentez :

mozilla index.html

Le résultat bien décevant est : www.index.html not found

La commande correcte permettant d'ouvrir le fichier dans une nouvelle tabulation si mozilla est lancée est :

mozilla -remote "openfile(usr/share/doc/mplayer-0.90/French/documentation.html, new-tab) "

Pratique, mais un peu long. Nous avons trouvé là un prétexte pour faire un script shell.

Enregistrez le script suivant dans un dossier se trouvant dans votre variable PATH, modifiez-en la troisième ligne, puis rendez-le exécutable grace à la commande :

chmod u+x html

Dorénavant, la commande html un_fichier.html lance mozilla pour afficher ce fichier, ou l'affiche dans un nouvel onglet si un navigateur est déjà lancé.

Le script html :

#!/bin/bash
# Script "html" : ouvre un fichier html dans mozilla dans un nouvel onglet.
export mozilla=/usr/local/bin/phoenix

# ESR veut une variable BROWSER comme il existe déjà
# $EDITOR et $VISUAL : http://www.tuxedo.org/~esr/BROWSER
test -x "$BROWSER" && mozilla="$BROWSER"

# Vérifions que le mozilla est bien un éxécutable:
test -x "$mozilla" || {
   echo "Impossible d'éxécuter le navigateur \"$mozilla\". Veuillez positionner la variable \$BROWSER"
exit 1
}

case "$1" in
   "" ) # pas de fichier
      echo "Usage : $0 fichier_html.html"
      exit 2 ;;
   /* ) # nom absolu
      fichier=$1 ;;
   * ) # nom local
      fichier=$PWD/$1 ;;
esac

# Vérifier que le fichier spécifié existe bien
test -r $fichier || {
   echo "Le fichier $fichier n'existe pas" ;
   exit 3 ;
}

$mozilla -remote "ping()"
if [ "$?" -eq 0 ]
then
   # un mozilla est déjà lancé : on ouvre le fichier dans une tabulation
   $mozilla -remote "openfile( $fichier , new-tab) "
else
   # on lance mozilla
   $mozilla "$fichier" &
fi