From 6130c3012f7bb8aca173a9ab082f3e4b25c0e4a8 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Thu, 12 Mar 2020 10:13:34 +0100 Subject: [PATCH] Function to test if argument is a remote URL --- send.to.0x0.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/send.to.0x0.sh b/send.to.0x0.sh index a69b7be..d1f3989 100755 --- a/send.to.0x0.sh +++ b/send.to.0x0.sh @@ -13,6 +13,7 @@ debug=true flag_clipboard=false flag_inline=false flag_file=false +flag_url=false null_service_url="https://null.101010.fr" @@ -43,6 +44,30 @@ is_file_exist() { fi } # ]]] +# Function to check if the argument looks like a remote URL [[[ +is_remote_url() { + _url="${1}" + + ## The variable will be considered as an URL if it's : + ## Start with 1 to 5 alpha caracters followed by "://" + ## Start with "www" + if printf -- '%s' "${_url}" | grep -q -E -- "^([[:alpha:]]{1,5}://|www)" + then + ### Verify doesn't already comes from the 0x0 service + if printf -- '%s' "${_url}" | grep -q -E -- "${null_service_url}" + then + flag_url=true + debug_message "− Func is_remote_url : The url (${_url}) seems to already point to the 0x0 service (${null_service_url})." + else + flag_url=false + debug_message "− Func is_remote_url : The url (${_url}) seems to be a remote url." + fi + else + debug_message "− Func is_remote_url : The content is not an URL." + fi + +} +# ]]] # Function to get content type [[[ determine_content_type() { _content="${1}" @@ -54,8 +79,8 @@ determine_content_type() { if [ "${_content_nb_line}" -eq "1" ]; then ### Verify if it's a path to a existent file is_file_exist "${_content}" - ### Verify it it's a remote URL - flag_url="" + ### Verify if it's a remote URL + is_remote_url "${_content}" fi } # ]]]