Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Windows root path and cmd with echo #268

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lua/sf/sub/raw_term.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ function T:run_after_setup(cmd, cb)
api.nvim_set_current_win(self.win)

local echo_msg = string.gsub(cmd, '"', '\\"')
local cmd_with_echo = string.format('echo -e "\\e[0;35m %s \\e[0m";%s', echo_msg, cmd) -- echo Cyan color
local cmd_with_echo = ''

if H.is_windows_os() then
local c27 = string.char(27)
cmd_with_echo = string.format('echo %s && %s', c27 .. '[0;35m' .. echo_msg .. c27 .. '[0m', cmd)
else
cmd_with_echo = string.format('echo -e "\\e[0;35m %s \\e[0m";%s', echo_msg, cmd) -- echo Cyan color
end
-- local cmd_with_echo = string.format('echo -e "\\e[0;35m %s \\e[0m";%s', echo_msg, cmd) -- echo Cyan color
vim.fn.termopen(cmd_with_echo, {
clear_env = self.config.clear_env,
env = self.config.env,
Expand Down Expand Up @@ -213,4 +221,11 @@ function H.get_dimension(opts)
}
end

function H.is_windows_os()
if vim.fn.has("win32") then
return true
end
return false
end

return T
5 changes: 4 additions & 1 deletion lua/sf/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ end
M.get_default_dir_path = function()
local dir_path = M.get_sf_root() .. vim.g.sf.default_dir
dir_path = dir_path:gsub("//", "/")
if dir_path:sub(1, 1) ~= "/" and dir_path:sub(1, 1) ~= "." then
if M.is_windows_os() then
dir_path = dir_path:gsub("\\", "/")
end
if dir_path:sub(1, 1) ~= "/" and dir_path:sub(1, 1) ~= "." and not M.is_windows_os() then
dir_path = "/" .. dir_path
end
if dir_path:sub(-1) ~= "/" then
Expand Down
Loading