further shell perf improvements for git and tags

main
bhagwan 3 years ago
parent abd1a3cc90
commit fad1ef47e3

@ -306,20 +306,21 @@ end
M.git_switch = function(selected, opts)
local cmd = path.git_cwd("git checkout ", opts.cwd)
local cmd = path.git_cwd({"git", "checkout"}, opts.cwd)
local git_ver = utils.git_version()
-- git switch was added with git version 2.23
if git_ver and git_ver >= 2.23 then
cmd = path.git_cwd("git switch ", opts.cwd)
cmd = path.git_cwd({"git", "switch"}, opts.cwd)
end
-- remove anything past space
local branch = selected[1]:match("[^ ]+")
-- do nothing for active branch
if branch:find("%*") ~= nil then return end
local args = ""
local is_remote = branch:find("^remotes/") ~= nil
if is_remote then args = "--detach " end
local output = vim.fn.systemlist(cmd .. args .. branch)
if branch:find("^remotes/") then
table.insert(cmd, "--detach")
end
table.insert(cmd, branch)
local output = utils.io_systemlist(cmd)
if utils.shell_error() then
utils.err(unpack(output))
else
@ -329,13 +330,14 @@ M.git_switch = function(selected, opts)
end
M.git_checkout = function(selected, opts)
local cmd_checkout = path.git_cwd("git checkout ", opts.cwd)
local cmd_cur_commit = path.git_cwd("git rev-parse --short HEAD", opts.cwd)
local cmd_checkout = path.git_cwd({"git", "checkout"}, opts.cwd)
local cmd_cur_commit = path.git_cwd({"git", "rev-parse", "--short HEAD"}, opts.cwd)
local commit_hash = selected[1]:match("[^ ]+")
if vim.fn.input("Checkout commit " .. commit_hash .. "? [y/n] ") == "y" then
local current_commit = vim.fn.systemlist(cmd_cur_commit)
local current_commit = utils.io_systemlist(cmd_cur_commit)
if(commit_hash == current_commit) then return end
local output = vim.fn.systemlist(cmd_checkout .. commit_hash)
table.insert(cmd_checkout, commit_hash)
local output = utils.io_systemlist(cmd_checkout)
if utils.shell_error() then
utils.err(unpack(output))
else
@ -346,13 +348,14 @@ M.git_checkout = function(selected, opts)
end
M.git_buf_edit = function(selected, opts)
local cmd = path.git_cwd("git show ", opts.cwd)
local cmd = path.git_cwd({"git", "show"}, opts.cwd)
local git_root = path.git_root(opts.cwd, true)
local win = vim.api.nvim_get_current_win()
local buffer_filetype = vim.bo.filetype
local file = path.relative(vim.fn.expand("%:p"), git_root)
local commit_hash = selected[1]:match("[^ ]+")
local git_file_contents = vim.fn.systemlist(cmd .. commit_hash .. ":" .. file)
table.insert(cmd, commit_hash .. ":" .. file)
local git_file_contents = utils.io_systemlist(cmd)
local buf = vim.api.nvim_create_buf(true, true)
local file_name = string.gsub(file,"$","[" .. commit_hash .. "]")
vim.api.nvim_buf_set_lines(buf,0,0,true,git_file_contents)

@ -516,6 +516,7 @@ function Previewer.man_pages:populate_preview_buf(entry_str)
-- mark the buffer for unloading the next call
self.preview_bufloaded = true
local cmd = self.cmd:format(entry)
if type(cmd) == 'string' then cmd = {"sh", "-c", cmd} end
local output, _ = utils.io_systemlist(cmd)
-- vim.api.nvim_buf_set_option(self.preview_bufnr, 'modifiable', true)
vim.api.nvim_buf_set_lines(self.preview_bufnr, 0, -1, false, output)

@ -9,9 +9,9 @@ local grep_cmd = nil
local get_grep_cmd = function()
if vim.fn.executable("rg") == 1 then
return "rg --line-number"
return {"rg", "--line-number"}
end
return "grep -n -P"
return {"grep", "-n", "-P"}
end
local fzf_tags = function(opts)
@ -81,10 +81,10 @@ local fzf_tags = function(opts)
-- equivalent pattern to `rg --crlf`
-- see discussion in #219
pattern = pattern:gsub("\\%$$", "\\r??%$")
local cmd = string.format('%s "%s" %s',
grep_cmd, pattern,
vim.fn.shellescape(filepath))
local out = vim.fn.system(cmd)
local cmd = utils.tbl_deep_clone(grep_cmd)
table.insert(cmd, pattern)
table.insert(cmd, filepath)
local out = utils.io_system(cmd)
if not utils.shell_error() then
line = out:match("[^:]+")
end

Loading…
Cancel
Save