Skip to content

Commit

Permalink
feat: add git_root save key support
Browse files Browse the repository at this point in the history
  • Loading branch information
sQVe committed Mar 15, 2024
1 parent 9712f85 commit f88767f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions lua/arrow/git.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local M = {}

local config = require("arrow.config")

function M.get_git_branch()
Expand Down
8 changes: 7 additions & 1 deletion lua/arrow/save_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ function M.cwd()
end

function M.git_root()
return vim.fn.system("git rev-parse --show-toplevel | tr -d '\n'")
local git_root = vim.fn.system("git rev-parse --show-toplevel 2>&1")

if vim.v.shell_error == 0 then
return git_root:gsub("\n$", "")
end

return M.cwd()
end

return M
3 changes: 1 addition & 2 deletions lua/arrow/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ function M.openFile(fileNumber, previousFile)
end

closeMenu()

action(fileName, vim.b.filename)
action(config.getState('save_key')() .. '/' .. fileName, vim.b.filename)
end
end

Expand Down
6 changes: 4 additions & 2 deletions lua/arrow/utils.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local M = {}

local config = require("arrow.config")

function M.join_two_keys_tables(tableA, tableB)
local newTable = {}

Expand Down Expand Up @@ -31,9 +33,9 @@ end
function M.get_path_for(buffer)
local bufname = vim.fn.bufname(buffer)

local cwd = vim.fn.getcwd()
local save_key = config.getState("save_key")()

local escaped_cwd = cwd:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")
local escaped_cwd = save_key:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")

if bufname:find("^" .. escaped_cwd .. "/") then
local relative_path = bufname:gsub("^" .. escaped_cwd .. "/", "")
Expand Down

0 comments on commit f88767f

Please sign in to comment.