Fix preview support for MS Windows (WSL and Git bash) (#1215)

* Fixes #1212

* Path translation only when containing backslash.

- lower letters also allowed for drive

Co-authored-by: Jan Stocker <Jan.Stocker@cosmoconsult.com>
This commit is contained in:
Grueslayer
2021-02-01 11:48:25 +01:00
committed by GitHub
parent 707f5b6269
commit 68ab645574
2 changed files with 21 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ IFS=':' read -r -a INPUT <<< "$1"
FILE=${INPUT[0]}
CENTER=${INPUT[1]}
if [[ $1 =~ ^[A-Z]:\\ ]]; then
if [[ $1 =~ ^[A-Za-z]:\\ ]]; then
FILE=$FILE:${INPUT[1]}
CENTER=${INPUT[2]}
fi
@@ -28,6 +28,20 @@ if [[ -n "$CENTER" && ! "$CENTER" =~ ^[0-9] ]]; then
fi
CENTER=${CENTER/[^0-9]*/}
# MS Win support
if [[ $FILE =~ '\' ]]; then
if [ -z "$MSWINHOME" ]; then
MSWINHOME="$HOMEDRIVE$HOMEPATH"
fi
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
MSWINHOME="${MSWINHOME//\\/\\\\}"
FILE="${FILE/#\~\\/$MSWINHOME\\}"
FILE=$(wslpath -u "$FILE")
elif [ -n "$MSWINHOME" ]; then
FILE="${FILE/#\~\\/$MSWINHOME\\}"
fi
fi
FILE="${FILE/#\~\//$HOME/}"
if [ ! -r "$FILE" ]; then
echo "File not found ${FILE}"