améliorer l'affichage des scripts geturl et openurl

This commit is contained in:
Jephté Clain 2015-07-22 12:28:52 +04:00
parent 0a6a8b218c
commit fb6b492d5c
3 changed files with 26 additions and 5 deletions

17
caturl
View File

@ -10,8 +10,10 @@ USAGE
$scriptname <file.url|file.desktop|URL>"
}
check=
parse_opts "${PRETTYOPTS[@]}" \
--help '$exit_with display_help' \
--check check=1 \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
function findurl() {
@ -25,7 +27,10 @@ if [ -z "$URL" ]; then
# Essayer de trouver une fichier homepage.{url,desktop} dans le répertoire
# courant
URLFILE="$(findurl homepage)"
[ -f "$URLFILE" ] || die "Il faut spécifier l'url à ouvrir"
if [ ! -f "$URLFILE" ]; then
[ -n "$check" ] && exit 2
die "Il faut spécifier l'url à ouvrir"
fi
elif [ -d "$URL" ]; then
# répertoire dans lequel se trouve éventuellement un fichier
# homepage.{url,desktop}
@ -63,7 +68,10 @@ if [ -n "$URLFILE" ]; then
/[uU][rR][lL]=/ { URL = substr($0, 5) }
END { if (type == 1) print URL }
')"
[ -n "$URL" ] || die "$URLFILE: ne contient pas d'URL"
if [ -z "$URL" ]; then
[ -n "$check" ] && exit 3
die "$URLFILE: ne contient pas d'URL"
fi
elif [ "${URLFILE%.desktop}" != "$URL" ]; then
# raccourci vers une url de XDG
URL="$(<"$URLFILE" awk 'BEGIN { type = 0; URL = "" }
@ -72,7 +80,10 @@ END { if (type == 1) print URL }
/[uU][rR][lL]=/ { URL = substr($0, 5) }
END { if (type == 2) print URL }
')"
[ -n "$URL" ] || die "$URLFILE: ne contient pas d'URL"
if [ -z "$URL" ]; then
[ -n "$check" ] && exit 3
die "$URLFILE: ne contient pas d'URL"
fi
fi
fi

7
geturl
View File

@ -14,7 +14,12 @@ parse_opts + "${PRETTYOPTS[@]}" \
--help '$exit_with display_help' \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
url="$("$scriptdir/caturl" "$1")" || die
"$scriptdir/caturl" --check "$1"
case $? in
2) die "Vous devez spécifier l'url à ouvrir";;
3) die "Le fichier spécifié ne contient pas d'url";;
esac
setx url="$scriptdir/caturl" "$1" || die
shift
filename="$(basename "$url")"

View File

@ -14,7 +14,12 @@ parse_opts "${PRETTYOPTS[@]}" \
--help '$exit_with display_help' \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
url="$("$scriptdir/caturl" "$1")" || die
"$scriptdir/caturl" --check "$1"
case $? in
2) die "Vous devez spécifier l'url à ouvrir";;
3) die "Le fichier spécifié ne contient pas d'url";;
esac
setx url="$scriptdir/caturl" "$1" || die
if progexists xdg-open; then
exec xdg-open "$url"