mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-02-22 15:57:09 +00:00
cleanup util
This commit is contained in:
parent
edbc935f50
commit
fad9ae1c15
2
lua/gitsigns/diff_ext.lua
generated
2
lua/gitsigns/diff_ext.lua
generated
@ -30,8 +30,8 @@ M.run_diff = function(
|
|||||||
|
|
||||||
local results = {}
|
local results = {}
|
||||||
|
|
||||||
if not util.is_unix then
|
|
||||||
|
|
||||||
|
if vim.in_fast_event() then
|
||||||
scheduler()
|
scheduler()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
33
lua/gitsigns/util.lua
generated
33
lua/gitsigns/util.lua
generated
@ -2,30 +2,23 @@ local M = {}
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function M.path_exists(path)
|
function M.path_exists(path)
|
||||||
return vim.loop.fs_stat(path) and true or false
|
return vim.loop.fs_stat(path) and true or false
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_jit_os()
|
|
||||||
if jit then
|
|
||||||
return jit.os:lower()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local jit_os
|
local jit_os
|
||||||
|
|
||||||
if jit then
|
if jit then
|
||||||
jit_os = jit.os:lower()
|
jit_os = jit.os:lower()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.is_unix = (function()
|
local is_unix = false
|
||||||
if jit_os == 'linux' or jit_os == 'osx' or jit_os == 'bsd' then
|
if jit_os then
|
||||||
return true
|
is_unix = jit_os == 'linux' or jit_os == 'osx' or jit_os == 'bsd'
|
||||||
end
|
else
|
||||||
return false
|
local binfmt = package.cpath:match("%p[\\|/]?%p(%a+)")
|
||||||
end)()
|
is_unix = binfmt ~= "dll"
|
||||||
|
end
|
||||||
|
|
||||||
function M.dirname(file)
|
function M.dirname(file)
|
||||||
return file:match(string.format('^(.+)%s[^%s]+', M.path_sep, M.path_sep))
|
return file:match(string.format('^(.+)%s[^%s]+', M.path_sep, M.path_sep))
|
||||||
@ -39,18 +32,10 @@ function M.file_lines(file)
|
|||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
M.path_sep = (function()
|
M.path_sep = package.config:sub(1, 1)
|
||||||
if jit_os then
|
|
||||||
if M.is_unix then
|
|
||||||
return '/'
|
|
||||||
end
|
|
||||||
return '\\'
|
|
||||||
end
|
|
||||||
return package.config:sub(1, 1)
|
|
||||||
end)()
|
|
||||||
|
|
||||||
function M.tmpname()
|
function M.tmpname()
|
||||||
if M.is_unix then
|
if is_unix then
|
||||||
return os.tmpname()
|
return os.tmpname()
|
||||||
end
|
end
|
||||||
return vim.fn.tempname()
|
return vim.fn.tempname()
|
||||||
|
@ -30,8 +30,8 @@ M.run_diff = function(
|
|||||||
): {Hunk}
|
): {Hunk}
|
||||||
local results: {Hunk} = {}
|
local results: {Hunk} = {}
|
||||||
|
|
||||||
if not util.is_unix then
|
-- tmpname must not be called in a callback
|
||||||
-- tmpname must not be called in a callback on windows
|
if vim.in_fast_event() then
|
||||||
scheduler()
|
scheduler()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,31 +1,24 @@
|
|||||||
local record M
|
local record M
|
||||||
path_sep: string
|
path_sep: string
|
||||||
is_unix: boolean
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.path_exists(path: string): boolean
|
function M.path_exists(path: string): boolean
|
||||||
return vim.loop.fs_stat(path) and true or false
|
return vim.loop.fs_stat(path) and true or false
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_jit_os(): string
|
|
||||||
if jit then
|
|
||||||
return jit.os:lower()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local jit_os: string
|
local jit_os: string
|
||||||
|
|
||||||
if jit then
|
if jit then
|
||||||
jit_os = jit.os:lower()
|
jit_os = jit.os:lower()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.is_unix = (function(): boolean
|
local is_unix: boolean = false
|
||||||
if jit_os == 'linux' or jit_os == 'osx' or jit_os == 'bsd' then
|
if jit_os then
|
||||||
return true
|
is_unix = jit_os == 'linux' or jit_os == 'osx' or jit_os == 'bsd'
|
||||||
end
|
else
|
||||||
return false
|
local binfmt = package.cpath:match("%p[\\|/]?%p(%a+)")
|
||||||
end)()
|
is_unix = binfmt ~= "dll"
|
||||||
|
end
|
||||||
|
|
||||||
function M.dirname(file: string): string
|
function M.dirname(file: string): string
|
||||||
return file:match(string.format('^(.+)%s[^%s]+', M.path_sep, M.path_sep))
|
return file:match(string.format('^(.+)%s[^%s]+', M.path_sep, M.path_sep))
|
||||||
@ -39,18 +32,10 @@ function M.file_lines(file: string): {string}
|
|||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
M.path_sep = (function(): string
|
M.path_sep = package.config:sub(1, 1)
|
||||||
if jit_os then
|
|
||||||
if M.is_unix then
|
|
||||||
return '/'
|
|
||||||
end
|
|
||||||
return '\\'
|
|
||||||
end
|
|
||||||
return package.config:sub(1, 1)
|
|
||||||
end)()
|
|
||||||
|
|
||||||
function M.tmpname(): string
|
function M.tmpname(): string
|
||||||
if M.is_unix then
|
if is_unix then
|
||||||
return os.tmpname()
|
return os.tmpname()
|
||||||
end
|
end
|
||||||
return vim.fn.tempname()
|
return vim.fn.tempname()
|
||||||
|
Loading…
Reference in New Issue
Block a user