Skip to content

Commit

Permalink
fix: 'system' function is now independent of the 'shell' option.
Browse files Browse the repository at this point in the history
  • Loading branch information
obaland committed Apr 1, 2023
1 parent 851ae56 commit f554e95
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 1 addition & 2 deletions lua/vfiler/items/file.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local core = require('vfiler/libs/core')
local fs = require('vfiler/libs/filesystem')
local vim = require('vfiler/libs/vim')

local File = {}

Expand All @@ -13,7 +12,7 @@ function File.create(path)
command = ('touch "%s"'):format(path)
end

local result = vim.fn.system(command)
local result = core.system(command)
if #result > 0 then
return nil
end
Expand Down
17 changes: 17 additions & 0 deletions lua/vfiler/libs/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ function M.try(block)
end
end

function M.system(expr)
local shell = vim.get_option('shell')
M.try({
function()
if M.is_windows then
vim.set_option('shell', 'cmd.exe')
else
vim.set_option('shell', '$SHELL')
end
vim.fn.system(expr)
end,
finally = function()
vim.set_option('shell', shell)
end,
})
end

------------------------------------------------------------------------------
-- Cursor
------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions lua/vfiler/libs/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ end

function M.copy_directory(src, dest)
local command = copy_directory_format:format(escape(src), escape(dest))
return vim.fn.system(command)
return core.system(command)
end

function M.copy_file(src, dest)
local command = copy_file_format:format(escape(src), escape(dest))
return vim.fn.system(command)
return core.system(command)
end

function M.execute(path)
Expand Down Expand Up @@ -234,7 +234,7 @@ function M.execute(path)
core.message.error('Not supported platform.')
return
end
vim.fn.system(command)
M.system(command)
end

function M.move(src, dest)
Expand Down
2 changes: 1 addition & 1 deletion lua/vfiler/libs/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end

function M.get_toplevel(dirpath)
local command = ('git -C "%s" rev-parse --show-toplevel'):format(dirpath)
local path = vim.fn.system(command)
local path = core.system(command)
if (not path or #path == 0) or path:match('^fatal') then
return nil
end
Expand Down

0 comments on commit f554e95

Please sign in to comment.