docs: update README.md
parent
03990e44c3
commit
5593b1b8f1
81
README.md
81
README.md
|
|
@ -367,15 +367,21 @@ The plugin also comes with pre-defined highlight groups for the Telescope implem
|
||||||
|
|
||||||
The plugin has been designed to be fully extensible. All of the functions in the [init.lua](https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/init.lua) and [utils.lua](https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua) file are public.
|
The plugin has been designed to be fully extensible. All of the functions in the [init.lua](https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/init.lua) and [utils.lua](https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua) file are public.
|
||||||
|
|
||||||
Consider a user who wishes to autoload a session if arguments are passed to Neovim. A custom autocmd can be created which forces the autoload (thanks to [neandrake](https://github.com/neandrake) for this solution):
|
**Custom Autoloading** by [neandrake](https://github.com/neandrake)
|
||||||
|
|
||||||
|
Autoloading a session if arguments are passed to Neovim:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
{
|
||||||
|
"olimorris/persisted.nvim",
|
||||||
|
lazy = false,
|
||||||
|
opts = {
|
||||||
|
autoload = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Somewhere in your config
|
||||||
local persisted = require("persisted")
|
local persisted = require("persisted")
|
||||||
|
|
||||||
persisted.setup({
|
|
||||||
autoload = true
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("VimEnter", {
|
vim.api.nvim_create_autocmd("VimEnter", {
|
||||||
nested = true,
|
nested = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
@ -402,23 +408,54 @@ vim.api.nvim_create_autocmd("VimEnter", {
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, a user who wishes to check whether the current branch is in a table of branches to be ignored:
|
**Git Branching from directories that are not the CWD** by [mrloop](https://github.com/mrloop)
|
||||||
|
|
||||||
|
As per [#149](https://github.com/olimorris/persisted.nvim/discussions/149), if you invoke Neovim from a sub-directory then the git branch will not be detected. The code below amends for this:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local persisted = require("persisted")
|
{
|
||||||
local utils = require("persisted.utils")
|
"olimorris/persisted.nvim",
|
||||||
|
lazy = false,
|
||||||
persisted.setup({
|
opts = {
|
||||||
autostart = false,
|
autoload = true,
|
||||||
use_git_branch = true,
|
autosave = true,
|
||||||
})
|
use_git_branch = true,
|
||||||
|
},
|
||||||
local ignored_branches = {
|
config = function(_, opts)
|
||||||
"feature_branch"
|
local persisted = require("persisted")
|
||||||
|
persisted.branch = function()
|
||||||
|
local branch = vim.fn.systemlist("git branch --show-current")[1]
|
||||||
|
return vim.v.shell_error == 0 and branch or nil
|
||||||
|
end
|
||||||
|
persisted.setup(opts)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Ignore Branches**
|
||||||
|
|
||||||
|
If you'd like to ignore certain branches from being saved as a session:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
"olimorris/persisted.nvim",
|
||||||
|
lazy = false,
|
||||||
|
opts = {
|
||||||
|
autostart = true,
|
||||||
|
use_git_branch = true,
|
||||||
|
},
|
||||||
|
config = function(_, opts)
|
||||||
|
local persisted = require("persisted")
|
||||||
|
local utils = require("persisted.utils")
|
||||||
|
local ignored_branches = {
|
||||||
|
"feature_branch"
|
||||||
|
}
|
||||||
|
|
||||||
|
persisted.setup(opts)
|
||||||
|
if not utils.in_table(persisted.branch(), ignored_branches) then
|
||||||
|
persisted.load()
|
||||||
|
persisted.start()
|
||||||
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
if not utils.in_table(persisted.branch(), ignored_branches) then
|
|
||||||
persisted.load()
|
|
||||||
persisted.start()
|
|
||||||
end
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -387,17 +387,21 @@ and utils.lua
|
||||||
<https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua>
|
<https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua>
|
||||||
file are public.
|
file are public.
|
||||||
|
|
||||||
Consider a user who wishes to autoload a session if arguments are passed to
|
**Custom Autoloading** by neandrake <https://github.com/neandrake>
|
||||||
Neovim. A custom autocmd can be created which forces the autoload (thanks to
|
|
||||||
neandrake <https://github.com/neandrake> for this solution):
|
Autoloading a session if arguments are passed to Neovim:
|
||||||
|
|
||||||
>lua
|
>lua
|
||||||
|
{
|
||||||
|
"olimorris/persisted.nvim",
|
||||||
|
lazy = false,
|
||||||
|
opts = {
|
||||||
|
autoload = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Somewhere in your config
|
||||||
local persisted = require("persisted")
|
local persisted = require("persisted")
|
||||||
|
|
||||||
persisted.setup({
|
|
||||||
autoload = true
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("VimEnter", {
|
vim.api.nvim_create_autocmd("VimEnter", {
|
||||||
nested = true,
|
nested = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
@ -424,26 +428,59 @@ neandrake <https://github.com/neandrake> for this solution):
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
|
|
||||||
Or, a user who wishes to check whether the current branch is in a table of
|
**Git Branching from directories that are not the CWD** by mrloop
|
||||||
branches to be ignored:
|
<https://github.com/mrloop>
|
||||||
|
|
||||||
|
As per #149 <https://github.com/olimorris/persisted.nvim/discussions/149>, if
|
||||||
|
you invoke Neovim from a sub-directory then the git branch will not be
|
||||||
|
detected. The code below amends for this:
|
||||||
|
|
||||||
>lua
|
>lua
|
||||||
local persisted = require("persisted")
|
{
|
||||||
local utils = require("persisted.utils")
|
"olimorris/persisted.nvim",
|
||||||
|
lazy = false,
|
||||||
persisted.setup({
|
opts = {
|
||||||
autostart = false,
|
autoload = true,
|
||||||
use_git_branch = true,
|
autosave = true,
|
||||||
})
|
use_git_branch = true,
|
||||||
|
},
|
||||||
local ignored_branches = {
|
config = function(_, opts)
|
||||||
"feature_branch"
|
local persisted = require("persisted")
|
||||||
|
persisted.branch = function()
|
||||||
|
local branch = vim.fn.systemlist("git branch --show-current")[1]
|
||||||
|
return vim.v.shell_error == 0 and branch or nil
|
||||||
|
end
|
||||||
|
persisted.setup(opts)
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
**Ignore Branches**
|
||||||
|
|
||||||
|
If you’d like to ignore certain branches from being saved as a session:
|
||||||
|
|
||||||
|
>lua
|
||||||
|
{
|
||||||
|
"olimorris/persisted.nvim",
|
||||||
|
lazy = false,
|
||||||
|
opts = {
|
||||||
|
autostart = true,
|
||||||
|
use_git_branch = true,
|
||||||
|
},
|
||||||
|
config = function(_, opts)
|
||||||
|
local persisted = require("persisted")
|
||||||
|
local utils = require("persisted.utils")
|
||||||
|
local ignored_branches = {
|
||||||
|
"feature_branch"
|
||||||
|
}
|
||||||
|
|
||||||
if not utils.in_table(persisted.branch(), ignored_branches) then
|
persisted.setup(opts)
|
||||||
persisted.load()
|
if not utils.in_table(persisted.branch(), ignored_branches) then
|
||||||
persisted.start()
|
persisted.load()
|
||||||
end
|
persisted.start()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
|
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue