2013-08-27 15:14:44 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
2014-07-07 22:06:38 +04:00
|
|
|
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
|
|
|
urequire DEFAULTS
|
2013-08-27 15:14:44 +04:00
|
|
|
|
|
|
|
function display_help() {
|
|
|
|
uecho "$scriptname: Afficher une url
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$scriptname <file.url|file.desktop|URL>"
|
|
|
|
}
|
|
|
|
|
2015-07-22 12:28:52 +04:00
|
|
|
check=
|
2013-08-27 15:14:44 +04:00
|
|
|
parse_opts "${PRETTYOPTS[@]}" \
|
|
|
|
--help '$exit_with display_help' \
|
2015-07-22 12:28:52 +04:00
|
|
|
--check check=1 \
|
2013-08-27 15:14:44 +04:00
|
|
|
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
|
|
|
|
|
|
|
function findurl() {
|
|
|
|
echo "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
URL="$1"
|
|
|
|
URLFILE=
|
|
|
|
|
|
|
|
if [ -z "$URL" ]; then
|
|
|
|
# Essayer de trouver une fichier homepage.{url,desktop} dans le répertoire
|
|
|
|
# courant
|
|
|
|
URLFILE="$(findurl homepage)"
|
2015-07-22 12:28:52 +04:00
|
|
|
if [ ! -f "$URLFILE" ]; then
|
|
|
|
[ -n "$check" ] && exit 2
|
|
|
|
die "Il faut spécifier l'url à ouvrir"
|
|
|
|
fi
|
2013-08-27 15:14:44 +04:00
|
|
|
elif [ -d "$URL" ]; then
|
|
|
|
# répertoire dans lequel se trouve éventuellement un fichier
|
|
|
|
# homepage.{url,desktop}
|
|
|
|
URLFILE="$(findurl "$URL/homepage")"
|
|
|
|
if [ -f "$URLFILE" ]; then
|
|
|
|
# un fichier d'url valide
|
|
|
|
:
|
|
|
|
else
|
|
|
|
# un répertoire local à ouvrir
|
|
|
|
URLFILE=
|
|
|
|
URL="file://$(abspath "$URL")"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
URLFILE="$(findurl "$URL")"
|
|
|
|
if [ -f "$URLFILE" ]; then
|
|
|
|
# un fichier d'url valide
|
|
|
|
:
|
|
|
|
else
|
|
|
|
if [ -f "$URL" ]; then
|
|
|
|
# un fichier local à ouvrir
|
|
|
|
URL="file://$(abspath "$URL")"
|
|
|
|
else
|
|
|
|
# on assume que c'est une url standard
|
|
|
|
:
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$URLFILE" ]; then
|
|
|
|
# lire l'url dans un fichier
|
|
|
|
if [ "${URLFILE%.url}" != "$URL" ]; then
|
|
|
|
# raccourci vers une url de windows
|
|
|
|
URL="$(<"$URLFILE" awk 'BEGIN { type = 0; URL = "" }
|
|
|
|
tolower($0) == "[internetshortcut]" { type = type + 1 }
|
|
|
|
/[uU][rR][lL]=/ { URL = substr($0, 5) }
|
|
|
|
END { if (type == 1) print URL }
|
|
|
|
')"
|
2015-07-22 12:28:52 +04:00
|
|
|
if [ -z "$URL" ]; then
|
|
|
|
[ -n "$check" ] && exit 3
|
|
|
|
die "$URLFILE: ne contient pas d'URL"
|
|
|
|
fi
|
2013-08-27 15:14:44 +04:00
|
|
|
elif [ "${URLFILE%.desktop}" != "$URL" ]; then
|
|
|
|
# raccourci vers une url de XDG
|
|
|
|
URL="$(<"$URLFILE" awk 'BEGIN { type = 0; URL = "" }
|
|
|
|
tolower($0) == "[desktop entry]" { type = type + 1 }
|
|
|
|
/Type=Link/ { type = type + 1 }
|
|
|
|
/[uU][rR][lL]=/ { URL = substr($0, 5) }
|
|
|
|
END { if (type == 2) print URL }
|
|
|
|
')"
|
2015-07-22 12:28:52 +04:00
|
|
|
if [ -z "$URL" ]; then
|
|
|
|
[ -n "$check" ] && exit 3
|
|
|
|
die "$URLFILE: ne contient pas d'URL"
|
|
|
|
fi
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$URL"
|