From ec13cd3f042d35c87bddba6c727f5d98091ffe95 Mon Sep 17 00:00:00 2001 From: Luc Hermitte Date: Wed, 27 Dec 2023 01:19:29 +0100 Subject: [PATCH] BUG: Fix os#system() w/ env vars on windows When &shell is a Windows shell (cmd.exe), we need to use these to set variables they can understand. Neither command.com not powershell are properly supported at this moment Closes #19 --- autoload/lh/os.vim | 31 ++++++++++++++++++++++--------- autoload/lh/po.vim | 11 ++++++----- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/autoload/lh/os.vim b/autoload/lh/os.vim index c08be68..ee12872 100644 --- a/autoload/lh/os.vim +++ b/autoload/lh/os.vim @@ -4,10 +4,10 @@ " " License: GPLv3 with exceptions " -" Version: 4.6.4 -let s:k_version = 40604 +" Version: 5.4.0 +let s:k_version = 50400 " Created: 10th Apr 2012 -" Last Update: 29th Oct 2018 +" Last Update: 27th Dec 2023 "------------------------------------------------------------------------ " Description: " «description» @@ -200,7 +200,10 @@ endfunction " Function: lh#os#new_runner_script(command, env) {{{3 function! lh#os#new_runner_script(command, env) abort - let tmpname = tempname() + " Force .cmd extension as Windows's cmd.exe will only accept command + " files with this extension. Even with an explicit "cmd /c + " foobar.tmp.cmd", the .cmd extension is required. + let tmpname = tempname() . ".cmd" let result = lh#on#exit() \.register(':call delete('.string(tmpname).')') let result._script_name = tmpname @@ -214,9 +217,19 @@ function! lh#os#new_runner_script(command, env) abort let result._lines += ['#!'.(env.__shebang)] unlet env.__shebang endif - if lh#os#OnDOSWindows() && ! lh#os#system_detected() == 'unix' - let result._lines += map(items(env), 'set v:val[0]."=".v:val[1]') - else + if &shell =~? '\vcmd(.exe)?$' + " TODO: Support powershell! + let result._cmd = result._script_name + let result._lines += ["@echo off"] + let result._lines += map(items(env), '"set ".v:val[0]."=".v:val[1]') + elseif &shell =~? 'powershell' + let result._cmd = result._script_name + let result._lines += map(items(env), '"$Env:".v:val[0]."=".s:as_string(v:val[1])') + " Warning, the exact command needs to be compatible with powershell! + else " Expecting unix like shells + " It seems we still need to say bash will interpret the script, and no + " other option (even "-c") shall be used. + let result._cmd = &shell . ' ' . result._script_name let result._lines += map(items(env), '"export ".v:val[0]."=".s:as_string(v:val[1])') endif let result._lines += type(a:command) == type([]) ? a:command : [ a:command ] @@ -232,8 +245,8 @@ function! lh#os#new_runner_script(command, env) abort endfunction function! s:run_script() dict abort - call s:Verbose("%1", self._lines) - let r = system(&shell . ' ' . self._script_name) + call s:Verbose("execute -> %1 which contains: %2", self._cmd, self._lines) + let r = system(self._cmd) return r endfunction diff --git a/autoload/lh/po.vim b/autoload/lh/po.vim index 9a83656..56f0d25 100644 --- a/autoload/lh/po.vim +++ b/autoload/lh/po.vim @@ -2,10 +2,10 @@ " File: autoload/lh/po.vim {{{1 " Author: Luc Hermitte " -" Version: 4.5.0. -let s:k_version = '40500' +" Version: 5.4.0. +let s:k_version = '50400' " Created: 03rd Feb 2017 -" Last Update: 27th Jun 2018 +" Last Update: 27th Dec 2023 "------------------------------------------------------------------------ " Description: " Utility functions to handle Portable Object messages @@ -60,12 +60,13 @@ endfunction " Function: s:translate(id) {{{3 let s:k_cached_translations = {} function! s:translate(id) dict abort + " TODO: Skip translation if LANG is English/C let cache = lh#dict#let(s:k_cached_translations, self._env.LANG .'.'. self._env.TEXTDOMAIN, {}) if !has_key(cache, a:id) if executable('bash') let cache[a:id] = lh#os#system('bash -c '.shellescape('echo $"'.a:id.'"'), self._env) else - " TODO: support windows + " TODO: support pure windows w/o bash let cache[a:id] = a:id endif endif @@ -79,7 +80,7 @@ function! lh#po#context(...) abort let res._env.TEXTDOMAIN = get(a:, 1, 'vim') let res._env.TEXTDOMAINDIR = get(a:, 1, $VIMRUNTIME.'/lang') let res._env.LANG = exists('$LC_MESSAGES') ? $LC_MESSAGES : v:lang - let res.translate = function(s:getSNR('translate')) + let res.translate = function(s:getSNR('translate')) return res endfunction