Skip to content

Commit

Permalink
Better handling of wsl nastyness
Browse files Browse the repository at this point in the history
#1198 reports that cmd.exe
and powershell.exe might not be available in the WSL path. Try to use
absolute paths if relative ones do not work and provide better error
messages when this doesn't work.
  • Loading branch information
glacambre committed Oct 1, 2021
1 parent fa6406d commit a42bc8b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions autoload/firenvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,20 @@ function! s:get_windows_env_path(env) abort
endif
return expand(l:env)
endif
if s:is_wsl
if v:true
let l:env = a:env
if l:env[0] ==# '$'
let l:env = '%' . l:env[1:-1] . '%'
endif
let l:cmd_output = system(['cmd.exe', '/c', 'echo', l:env])
try
let l:cmd_output = system(['cmd.exe', '/c', 'echo', l:env])
catch /E475:.*cmd.exe' is not executable/
try
let l:cmd_output = system(['/mnt/c/Windows/System32/cmd.exe', '/c', 'echo', l:env])
catch /E475:.*cmd.exe' is not executable/
throw 'Error: Firenvim could not find cmd.exe from WSL on your system. Please report this issue.'
endtry
endtry
return cmd_output[match(l:cmd_output, 'C:\\'):-3]
endif
throw 'Used get_windows_env_path on non-windows platform!'
Expand Down Expand Up @@ -746,7 +754,29 @@ function! firenvim#install(...) abort
echo 'Creating registry key for ' . l:name . '. This may take a while. Script: ' . l:ps1_path
call s:maybe_execute('writefile', split(l:ps1_content, "\n"), l:ps1_path)
call s:maybe_execute('setfperm', l:ps1_path, 'rwx------')
let o = s:maybe_execute('system', ['powershell.exe', '-Command', '-'], readfile(l:ps1_path))
try
let o = s:maybe_execute('system', ['powershell.exe', '-Command', '-'], readfile(l:ps1_path))
catch /powershell.exe' is not executable/
let l:success = v:false
if s:is_wsl
try
let o = s:maybe_execute('system', ['/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe', '-Command', '-'], readfile(l:ps1_path))
let l:success = v:true
catch /powershell.exe' is not executable/
let l:success = v:false
endtry
endif
if !l:success
let l:msg = 'Error: Firenvim could not find powershell.exe'
if s:is_wsl
let l:msg += ' from WSL'
endif
let l:msg = ' on your system. Please report this issue.'
echomsg 'Note: created ' . l:ps1_path . " . You may try to run it manually by right-clicking from your file browser to complete Firenvim's installation."
throw l:msg
endif
endtry

if v:shell_error
echo o
endif
Expand Down

0 comments on commit a42bc8b

Please sign in to comment.