@@ -12,11 +12,18 @@ local function is_valid_file(path)
1212 return vim .fn .getfsize (path ) > 0
1313end
1414
15- --- Run shell command and return success
16- --- @param cmd string
15+ --- Run shell or powershell command and return success
16+ --- @param cmd string | table
17+ --- @param opts table ?
1718--- @return boolean
18- local function run_shell_cmd (cmd )
19- return vim .system ({ ' sh' , ' -c' , cmd }):wait ().code == 0
19+ local function run_shell_cmd (cmd , opts )
20+ local sys_cmd
21+ if type (cmd ) == ' string' then
22+ sys_cmd = { ' sh' , ' -c' , cmd }
23+ else
24+ sys_cmd = cmd
25+ end
26+ return vim .system (sys_cmd , opts ):wait ().code == 0
2027end
2128
2229--- Save base64 data to file
@@ -27,11 +34,10 @@ local function save_base64(data, path)
2734 if vim .fn .has (' win32' ) == 1 then
2835 local script =
2936 string.format (' [System.IO.File]::WriteAllBytes("%s", [System.Convert]::FromBase64String("%s"))' , path , data )
30- return vim . system ({ ' powershell.exe' , ' -command' , ' -' }, { stdin = script }): wait (). code == 0
37+ return run_shell_cmd ({ ' powershell.exe' , ' -command' , ' -' }, { stdin = script })
3138 else
3239 local decode_arg = vim .uv .os_uname ().sysname == ' Darwin' and ' -D' or ' -d'
33- return vim .system ({ ' sh' , ' -c' , string.format (' base64 %s > "%s"' , decode_arg , path ) }, { stdin = data }):wait ().code
34- == 0
40+ return run_shell_cmd (string.format (' base64 %s > "%s"' , decode_arg , path ), { stdin = data })
3541 end
3642end
3743
@@ -79,7 +85,7 @@ local function handle_windows_clipboard(path)
7985 ]] ,
8086 path
8187 )
82- return vim . system ({ ' powershell.exe' , ' -command' , ' -' }, { stdin = script }): wait (). code == 0
88+ return run_shell_cmd ({ ' powershell.exe' , ' -command' , ' -' }, { stdin = script })
8389end
8490
8591local handlers = {
0 commit comments