Skip to content

Commit

Permalink
fix: use noninteractive powershell
Browse files Browse the repository at this point in the history
This PR is a continuation of glacambre#1199 and glacambre#1577. glacambre#1199 adds support for
running `powershell.exe` when it's not in the path (this occurs when
WSL user sets `appendWindowsPath=false` in `/etc/wsl.conf`). glacambre#1577 adds
`-NonInteractive` option to `powershell.exe` commands.
  • Loading branch information
xudyang1 committed Jul 27, 2024
1 parent c6e3747 commit 4825d00
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions autoload/firenvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,9 @@ 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 l:o = ''
try
let o = s:maybe_execute('system', ['powershell.exe', '-NonInteractive', '-Command', '-'], readfile(l:ps1_path))
let l:o = s:maybe_execute('system', ['powershell.exe', '-NonInteractive', '-Command', '-'], readfile(l:ps1_path))
catch /powershell.exe' is not executable/
let l:failure = v:true
let l:msg = 'Error: Firenvim could not find powershell.exe'
Expand All @@ -957,7 +958,7 @@ function! firenvim#install(...) abort
if s:is_wsl
let l:msg += ' from WSL'
try
let o = s:maybe_execute('system', ['/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe', '-Command', '-'], readfile(l:ps1_path))
let l:o = s:maybe_execute('system', ['/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe', '-NonInteractive', '-Command', '-'], readfile(l:ps1_path))
let l:failure = v:false
catch /powershell.exe' is not executable/
let l:failure = v:true
Expand All @@ -971,7 +972,7 @@ function! firenvim#install(...) abort
endtry

if v:shell_error
echo o
echo l:o
endif

echo 'Created registry key for ' . l:name . '.'
Expand Down Expand Up @@ -1022,9 +1023,28 @@ function! firenvim#uninstall() abort
if has('win32') || s:is_wsl
echo 'Removing registry key for ' . l:name . '. This may take a while.'
let l:ps1_content = 'Remove-Item -Path "' . l:cur_browser['registry_key'] . '" -Recurse'
let o = system(['powershell.exe', '-NonInteractive', '-Command', '-'], [l:ps1_content])
let l:o = ''
try
let l:o = s:maybe_execute('system', ['powershell.exe', '-NonInteractive', '-Command', '-'], [l:ps1_content])
catch /powershell.exe' is not executable/
let l:failure = v:true
let l:msg = 'Error: Firenvim could not find powershell.exe'
" If the failure happened on wsl, try to use
" an absolute path
if s:is_wsl
let l:msg += ' from WSL'
try
let l:o = s:maybe_execute('system', ['/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe', '-NonInteractive', '-Command', '-'], [l:ps1_content])
let l:failure = v:false
catch /powershell.exe' is not executable/
let l:failure = v:true
endtry
endif
let l:msg += ' on your system. Please report this issue.'
endtry

if v:shell_error
echo o
echo l:o
endif
echo 'Removed registry key for ' . l:name . '.'
endif
Expand Down

0 comments on commit 4825d00

Please sign in to comment.