Commits

ZyX_I committed c26dce8

@/os: Improved newline handling in os.run(): now it uses :! if command contains newlines and system() otherwise

Comments (0)

Files changed (2)

plugin/frawor/os.vim

             \  'lazyredraw':   1,
         \}
 function s:os.run(command, ...)
+    let hasnewlines=!empty(filter(copy(a:command), 'stridx(v:val, "\n")>0'))
     if s:os.name is 'nt'
         let cmd=escape(a:command[0], '\ %')
         if len(a:command)>1
             let cmd.=' '.join(map(a:command[1:],
                         \'((v:val=~#"^[[:alnum:]/\\-]\\+$")?'.
                         \   '(v:val):'.
-                        \   '(shellescape(v:val)))'))
+                        \   '(shellescape(v:val, hasnewlines)))'))
         endif
     else
-        let cmd=join(map(copy(a:command), 'shellescape(v:val, 1)'))
+        let cmd=join(map(copy(a:command), 'shellescape(v:val, hasnewlines)'))
     endif
     try
         if a:0
                 return -1
             endif
         endif
-        execute 'silent! !'.cmd
+        if hasnewlines
+            execute 'silent! !'.cmd
+        else
+            call system(cmd)
+        endif
         redraw!
         return v:shell_error
     finally
Binary file modified.