repo: uritools action: blob revision: path_from: uri-absolution revision_from: refs/heads/master: path_to: revision_to:
blob of:
/ uri-absolution
refs/heads/master:/uri-absolution
#!/bin/sh
if [ "$1" ];then
base_uri="$1"
else
base_uri="file:$(pwd)/"
fi
domain="$(printf "%s\n" "$base_uri" | uricut -d)"
port="$(printf "%s\n" "$base_uri" | uricut -P)"
if [ "$domain" ];then
if [ "$port" ];then
authority="//${domain}:${port}/"
else
authority="//${domain}/"
fi
else
authority=""
fi
scheme="$(printf "%s\n" "$base_uri" | uricut -s)"
path="$(printf "%s\n" "$base_uri" | uricut -p)"
most_of_path="$(printf "%s\n" "$base_uri" | uricut -p | rev | cut -d/ -f2- | rev)"
### this is the verbose version for debugging.
### to enable debug mode, uncomment this, and comment out the next sed.
#sed \
#'s|^<>$|(blank input) '"${base_uri}"'|g;t
#s|^<[ \t]*\([A-Za-z][A-Za-z+.-]*:[^ \t]*\)>|(absolute) \1|g;t
#s|^<[ \t]*\(#[^ \t]*\)>|(fragmentid_relative) '"${base_uri}"'\1|g;t
#s|^<[ \t]*\(?[^ \t]*\)>|(querystring_relative) '"$scheme"'://'"$domain""$path"'\1|g;t
#s|^<[ \t]*\(//[^ \t]*\)>|(scheme_relative) '"$scheme"':\1|g;t
#s|^<[ \t]*\(/[^ \t]*\)>|(absolute_path) '"$scheme"'://'"$domain"'\1|g;t
#s|^<[ \t]*\([^ \t]*\)>|(same-dir path relative) '"$scheme"'://'"$domain""$most_of_path"'/\1|g'
#exit 0
sed -u \
's|^<>$|'"${base_uri}"'|g;t
s|^<[ \t]*\([A-Za-z][A-Za-z+.-]*:[^ \t]*\)>|\1|g;t
s|^<[ \t]*\(#[^ \t]*\)>|'"${base_uri}"'\1|g;t
s|^<[ \t]*\(?[^ \t]*\)>|'"$scheme"':'"$authority""$path"'\1|g;t
s|^<[ \t]*\(//[^ \t]*\)>|'"$scheme"':\1|g;t
s|^<[ \t]*\(/[^ \t]*\)>|'"$scheme"':'"$authority"'\1|g;t
s|^<[ \t]*\([^ \t]*\)>|'"$scheme"':'"$authority""$most_of_path"'/\1|g;t
s|^<[ \t]*\(.*\)>|<\1> UNHANDLED|g'