summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlatian <baschdel@disroot.org>2023-10-04 19:12:57 +0200
committerSimon Lees <simon@simotek.net>2023-10-11 05:30:50 +0000
commit63aa25c2836f45f80e609ac81f2c6939ccb3a894 (patch)
tree59191b0a37dd5aec240b283eb086be23489b002f
parentfa2b74f11f7d9486a2394c3919901c889ef37e08 (diff)
Deduplicate URL recognition
-rwxr-xr-xscripts/xdg-open.in10
1 files changed, 7 insertions, 3 deletions
diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
index 2620959..52032c2 100755
--- a/scripts/xdg-open.in
+++ b/scripts/xdg-open.in
@@ -68,11 +68,15 @@ get_key()
IFS="${IFS_}"
}
+has_url_scheme()
+{
+ echo "$1" | grep -Eq '^[[:alpha:]][[:alpha:][:digit:]+\.\-]*:'
+}
+
# Returns true if argument is a file:// URL or path
is_file_url_or_path()
{
- if echo "$1" | grep -q '^file://' \
- || ! echo "$1" | LC_ALL=C grep -Eq '^[[:alpha:]][[:alpha:][:digit:]+\.\-]*:'; then
+ if echo "$1" | grep -q '^file://' || ! has_url_scheme "$1" ; then
return 0
else
return 1
@@ -442,7 +446,7 @@ open_envvar()
open_wsl()
{
- if [[ "$1" =~ '^[a-zA-Z]+://' ]]; then
+ if has_url_scheme "$1"; then
local win_path="$1"
else
local win_path="$(wslpath -aw "$1")"