92 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
 | |
| source "$(dirname "$0")/lib/ulib/ulib" || exit 1
 | |
| urequire DEFAULTS
 | |
| 
 | |
| function display_help() {
 | |
|     uecho "$scriptname: Afficher une url
 | |
| 
 | |
| 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() {
 | |
|     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)"
 | |
|     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}
 | |
|     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 }
 | |
| ')"
 | |
|         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 = "" }
 | |
|   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 }
 | |
| ')"
 | |
|         if [ -z "$URL" ]; then
 | |
|             [ -n "$check" ] && exit 3
 | |
|             die "$URLFILE: ne contient pas d'URL"
 | |
|         fi
 | |
|     fi
 | |
| fi
 | |
| 
 | |
| [ -n "$check" ] && exit 0
 | |
| echo "$URL"
 |