feat: telescope add/update branch name
parent
bcdada28d2
commit
a1cc308580
|
|
@ -42,7 +42,7 @@ Install the plugin with your preferred package manager:
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|
||||||
**Note:** The `lazy = true` option may be useful if you use a dashboard
|
**Note**The `lazy = true` option may be useful if you use a dashboard
|
||||||
**Packer**
|
**Packer**
|
||||||
|
|
||||||
>lua
|
>lua
|
||||||
|
|
@ -151,7 +151,8 @@ The plugin comes with the following defaults:
|
||||||
require("persisted").setup({
|
require("persisted").setup({
|
||||||
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
|
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
|
||||||
silent = false, -- silent nvim message when sourcing session file
|
silent = false, -- silent nvim message when sourcing session file
|
||||||
use_git_branch = false, -- create session files based on the branch of the git enabled repository
|
use_git_branch = false, -- create session files based on the branch of a git enabled repository
|
||||||
|
default_branch = "main", -- the branch to load if a session file is not found for the current branch
|
||||||
autosave = true, -- automatically save session files when exiting Neovim
|
autosave = true, -- automatically save session files when exiting Neovim
|
||||||
should_autosave = nil, -- function to determine if a session should be autosaved
|
should_autosave = nil, -- function to determine if a session should be autosaved
|
||||||
autoload = false, -- automatically load the session for the cwd on Neovim startup
|
autoload = false, -- automatically load the session for the cwd on Neovim startup
|
||||||
|
|
@ -159,8 +160,8 @@ The plugin comes with the following defaults:
|
||||||
follow_cwd = true, -- change session file name to match current working directory if it changes
|
follow_cwd = true, -- change session file name to match current working directory if it changes
|
||||||
allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
|
allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
|
||||||
ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading
|
ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading
|
||||||
telescope = { -- options for the telescope extension
|
telescope = {
|
||||||
reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted
|
reset_prompt = true, -- Reset prompt after a telescope action?
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
|
|
@ -202,10 +203,11 @@ files for a given project, by using git branches. To enable git branching:
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
|
|
||||||
If you switch branches in a repository, the plugin will try to load a session
|
|
||||||
which corresponds to that branch. If it can’t find one, then it will load the
|
|
||||||
session from the `main` branch.
|
|
||||||
|
|
||||||
|
**Note**If you initiate git in a repository which has an existing session file,
|
||||||
|
you’ll need to add it’s branch name to the session name. To do this from
|
||||||
|
within Neovim, use the `:Sessions` command, navigate to the session and press
|
||||||
|
`<C-a>`.
|
||||||
|
|
||||||
AUTOSAVING ~
|
AUTOSAVING ~
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,12 @@ local function search_sessions(opts)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_actions.add_branch:enhance({ post = refresh_sessions })
|
||||||
_actions.delete_session:enhance({ post = refresh_sessions })
|
_actions.delete_session:enhance({ post = refresh_sessions })
|
||||||
|
|
||||||
|
map("i", "<c-a>", function()
|
||||||
|
return _actions.add_branch(config)
|
||||||
|
end)
|
||||||
map("i", "<c-d>", _actions.delete_session)
|
map("i", "<c-d>", _actions.delete_session)
|
||||||
|
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ M.load_session = function(session, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Delete the selected session from disk
|
---Delete the selected session from disk
|
||||||
--@return string
|
--@return nil
|
||||||
M.delete_session = function()
|
M.delete_session = function()
|
||||||
local session = get_selected_session()
|
local session = get_selected_session()
|
||||||
local path = session.file_path
|
local path = session.file_path
|
||||||
|
|
@ -35,4 +35,32 @@ M.delete_session = function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Add a branch to an existing session
|
||||||
|
---@return nil
|
||||||
|
M.add_branch = function(config)
|
||||||
|
local session = get_selected_session()
|
||||||
|
local path = session.file_path
|
||||||
|
|
||||||
|
local branch = vim.fn.input("Branch name: ")
|
||||||
|
|
||||||
|
if vim.fn.confirm("Add/update branch to [" .. branch .. "]?", "&Yes\n&No") == 1 then
|
||||||
|
local ext = path:match("^.+(%..+)$")
|
||||||
|
|
||||||
|
-- Check for existing branch name in the filename
|
||||||
|
local branch_separator = config.branch_separator or "@@"
|
||||||
|
local pattern = "(.*)" .. branch_separator .. ".+" .. ext .. "$"
|
||||||
|
local base = path:match(pattern) or path:sub(1, #path - #ext)
|
||||||
|
|
||||||
|
-- Replace or add the new branch name
|
||||||
|
local new_path = ""
|
||||||
|
if branch == "" then
|
||||||
|
new_path = base .. ext
|
||||||
|
else
|
||||||
|
new_path = base .. branch_separator .. branch .. ext
|
||||||
|
end
|
||||||
|
|
||||||
|
os.rename(path, new_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return transform_mod(M)
|
return transform_mod(M)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue