mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 21:24:40 +08:00
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:
@@ -163,6 +163,12 @@ function! fzf#vim#with_preview(...)
|
|||||||
endif
|
endif
|
||||||
if s:is_win
|
if s:is_win
|
||||||
let is_wsl_bash = exepath('bash') =~? 'Windows[/\\]system32[/\\]bash.exe$'
|
let is_wsl_bash = exepath('bash') =~? 'Windows[/\\]system32[/\\]bash.exe$'
|
||||||
|
if empty($MSWINHOME)
|
||||||
|
let $MSWINHOME = $HOME
|
||||||
|
endif
|
||||||
|
if is_wsl_bash && $WSLENV !~# '[:]\?MSWINHOME\(\/[^:]*\)\?\(:\|$\)'
|
||||||
|
let $WSLENV = 'MSWINHOME/u:'.$WSLENV
|
||||||
|
endif
|
||||||
let preview_cmd = 'bash '.(is_wsl_bash
|
let preview_cmd = 'bash '.(is_wsl_bash
|
||||||
\ ? substitute(substitute(s:bin.preview, '^\([A-Z]\):', '/mnt/\L\1', ''), '\', '/', 'g')
|
\ ? substitute(substitute(s:bin.preview, '^\([A-Z]\):', '/mnt/\L\1', ''), '\', '/', 'g')
|
||||||
\ : escape(s:bin.preview, '\'))
|
\ : escape(s:bin.preview, '\'))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ IFS=':' read -r -a INPUT <<< "$1"
|
|||||||
FILE=${INPUT[0]}
|
FILE=${INPUT[0]}
|
||||||
CENTER=${INPUT[1]}
|
CENTER=${INPUT[1]}
|
||||||
|
|
||||||
if [[ $1 =~ ^[A-Z]:\\ ]]; then
|
if [[ $1 =~ ^[A-Za-z]:\\ ]]; then
|
||||||
FILE=$FILE:${INPUT[1]}
|
FILE=$FILE:${INPUT[1]}
|
||||||
CENTER=${INPUT[2]}
|
CENTER=${INPUT[2]}
|
||||||
fi
|
fi
|
||||||
@@ -28,6 +28,20 @@ if [[ -n "$CENTER" && ! "$CENTER" =~ ^[0-9] ]]; then
|
|||||||
fi
|
fi
|
||||||
CENTER=${CENTER/[^0-9]*/}
|
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/}"
|
FILE="${FILE/#\~\//$HOME/}"
|
||||||
if [ ! -r "$FILE" ]; then
|
if [ ! -r "$FILE" ]; then
|
||||||
echo "File not found ${FILE}"
|
echo "File not found ${FILE}"
|
||||||
|
|||||||
Reference in New Issue
Block a user