[bin] Use urldecode() to properly open weird file:/// or other URIs

This commit is contained in:
Sebastian Schulze 2023-01-10 00:18:24 +01:00
parent 563080b9c1
commit 73e38f4606
Signed by: bascht
GPG Key ID: 5BCB1D3B4D38A35A
1 changed files with 5 additions and 1 deletions

View File

@ -4,8 +4,12 @@ set -eo pipefail
export SWAYSOCK=/run/user/1000/sway-ipc.sock
# Kudos: https://stackoverflow.com/a/37840948
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
# Strip file:// protocol as file -b will handle this
argument=$(echo $1 | sed "s|file://||")
argument=$(urldecode "${1}" | sed "s|file://||")
url_regex='^(https?|alfaview|mailto|ftp):/?/?.*'
if [[ $argument =~ $url_regex ]]; then