commit 704c93d68cfb4a6eaf8abec717fefd6fdb4b94aa
parent 9ac3dfa35a3eff740197c11d0967770378b4d41b
Author: blmayer <bleemayer@gmail.com>
Date: Mon, 5 Jul 2021 23:33:09 -0300
Improved URL parsing
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/astro b/astro
@@ -38,8 +38,9 @@ version() {
# Parameters: url
parseurl() {
# Credits: https://stackoverflow.com/a/6174447/7618649
- proto="$(echo "$1" | grep :// | sed -e's,^\(.*\)://.*,\1,g')" # extract the protocol
- url="${1/"$proto://"/}" # remove the protocol
+ proto="$(echo "$1" | grep // | sed -e's,^\(.*:\?//\).*,\1,g')" # extract the protocol
+ url="${1/$proto/}" # remove the protocol
+ proto="$(echo "$proto" | sed -e 's,:\?//,,g')"
user="$(echo "$url" | grep @ | cut -d@ -f1)" # extract the user (if any)
hostport="$(echo "${url/$user@/}" | cut -d/ -f1)" # extract the host and port
host="$(echo "$hostport" | sed -e 's,:.*,,g')" # by request host without port