diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in index 4928538..8749f0b 100644 --- a/scripts/xdg-open.in +++ b/scripts/xdg-open.in @@ -399,6 +399,36 @@ open_envvar() done } +open_wsl() +{ + wsl_path_decode() + { + realpath="$(realpath "$1" 2> /dev/null)" + if [ $? -eq 0 ] && [ -e "$realpath" ]; then + case "$realpath" in + /mnt/*) + printf "%s" "$realpath" | sed -r 's|^/mnt/([^/]+)/?|\1:\\|;s|/|\\|g;s|\\\\|\\|g' + ;; + *) + exit_failure_operation_failed file path conversion failure: file not accessible by Windows + ;; + esac + else + # assume url + echo "$1" + fi + } + res="$(wsl_path_decode "$1")" + [ $? -eq 0 ] || exit_failure_operation_failed + powershell.exe start "${res}" + + if [ $? -eq 0 ]; then + exit_success + else + exit_failure_operation_failed + fi +} + open_generic() { if is_file_url_or_path "$1"; then @@ -568,6 +598,10 @@ case "$DE" in open_flatpak "$url" ;; + wsl) + open_wsl "$url" + ;; + generic) open_generic "$url" ;; diff --git a/scripts/xdg-utils-common.in b/scripts/xdg-utils-common.in index b4333e2..c02da68 100644 --- a/scripts/xdg-utils-common.in +++ b/scripts/xdg-utils-common.in @@ -349,6 +349,11 @@ detectDE() Darwin) DE=darwin; ;; + Linux) + grep -q Microsoft /proc/version > /dev/null 2>&1 && \ + which powershell.exe > /dev/null 2>&1 && \ + DE=wsl; + ;; esac fi