Skip to content

Commit 5593b1b

Browse files
committed
docs: update README.md
1 parent 03990e4 commit 5593b1b

File tree

2 files changed

+118
-44
lines changed

2 files changed

+118
-44
lines changed

README.md

+57-20
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,21 @@ The plugin also comes with pre-defined highlight groups for the Telescope implem
367367

368368
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.
369369

370-
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):
370+
**Custom Autoloading** by [neandrake](https://github.com/neandrake)
371371

372-
```lua
373-
local persisted = require("persisted")
372+
Autoloading a session if arguments are passed to Neovim:
374373

375-
persisted.setup({
376-
autoload = true
377-
})
374+
```lua
375+
{
376+
"olimorris/persisted.nvim",
377+
lazy = false,
378+
opts = {
379+
autoload = true,
380+
},
381+
}
378382

383+
-- Somewhere in your config
384+
local persisted = require("persisted")
379385
vim.api.nvim_create_autocmd("VimEnter", {
380386
nested = true,
381387
callback = function()
@@ -402,23 +408,54 @@ vim.api.nvim_create_autocmd("VimEnter", {
402408
})
403409
```
404410

405-
Or, a user who wishes to check whether the current branch is in a table of branches to be ignored:
411+
**Git Branching from directories that are not the CWD** by [mrloop](https://github.com/mrloop)
412+
413+
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:
406414

407415
```lua
408-
local persisted = require("persisted")
409-
local utils = require("persisted.utils")
416+
{
417+
"olimorris/persisted.nvim",
418+
lazy = false,
419+
opts = {
420+
autoload = true,
421+
autosave = true,
422+
use_git_branch = true,
423+
},
424+
config = function(_, opts)
425+
local persisted = require("persisted")
426+
persisted.branch = function()
427+
local branch = vim.fn.systemlist("git branch --show-current")[1]
428+
return vim.v.shell_error == 0 and branch or nil
429+
end
430+
persisted.setup(opts)
431+
end,
432+
}
433+
```
410434

411-
persisted.setup({
412-
autostart = false,
413-
use_git_branch = true,
414-
})
435+
**Ignore Branches**
415436

416-
local ignored_branches = {
417-
"feature_branch"
418-
}
437+
If you'd like to ignore certain branches from being saved as a session:
419438

420-
if not utils.in_table(persisted.branch(), ignored_branches) then
421-
persisted.load()
422-
persisted.start()
423-
end
439+
```lua
440+
{
441+
"olimorris/persisted.nvim",
442+
lazy = false,
443+
opts = {
444+
autostart = true,
445+
use_git_branch = true,
446+
},
447+
config = function(_, opts)
448+
local persisted = require("persisted")
449+
local utils = require("persisted.utils")
450+
local ignored_branches = {
451+
"feature_branch"
452+
}
453+
454+
persisted.setup(opts)
455+
if not utils.in_table(persisted.branch(), ignored_branches) then
456+
persisted.load()
457+
persisted.start()
458+
end
459+
end
460+
}
424461
```

doc/persisted.nvim.txt

+61-24
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,21 @@ and utils.lua
387387
<https://github.com/olimorris/persisted.nvim/blob/main/lua/persisted/utils.lua>
388388
file are public.
389389

390-
Consider a user who wishes to autoload a session if arguments are passed to
391-
Neovim. A custom autocmd can be created which forces the autoload (thanks to
392-
neandrake <https://github.com/neandrake> for this solution):
390+
**Custom Autoloading** by neandrake <https://github.com/neandrake>
391+
392+
Autoloading a session if arguments are passed to Neovim:
393393

394394
>lua
395-
local persisted = require("persisted")
396-
397-
persisted.setup({
398-
autoload = true
399-
})
395+
{
396+
"olimorris/persisted.nvim",
397+
lazy = false,
398+
opts = {
399+
autoload = true,
400+
},
401+
}
400402

403+
-- Somewhere in your config
404+
local persisted = require("persisted")
401405
vim.api.nvim_create_autocmd("VimEnter", {
402406
nested = true,
403407
callback = function()
@@ -424,26 +428,59 @@ neandrake <https://github.com/neandrake> for this solution):
424428
})
425429
<
426430

427-
Or, a user who wishes to check whether the current branch is in a table of
428-
branches to be ignored:
431+
**Git Branching from directories that are not the CWD** by mrloop
432+
<https://github.com/mrloop>
433+
434+
As per #149 <https://github.com/olimorris/persisted.nvim/discussions/149>, if
435+
you invoke Neovim from a sub-directory then the git branch will not be
436+
detected. The code below amends for this:
429437

430438
>lua
431-
local persisted = require("persisted")
432-
local utils = require("persisted.utils")
433-
434-
persisted.setup({
435-
autostart = false,
436-
use_git_branch = true,
437-
})
438-
439-
local ignored_branches = {
440-
"feature_branch"
439+
{
440+
"olimorris/persisted.nvim",
441+
lazy = false,
442+
opts = {
443+
autoload = true,
444+
autosave = true,
445+
use_git_branch = true,
446+
},
447+
config = function(_, opts)
448+
local persisted = require("persisted")
449+
persisted.branch = function()
450+
local branch = vim.fn.systemlist("git branch --show-current")[1]
451+
return vim.v.shell_error == 0 and branch or nil
452+
end
453+
persisted.setup(opts)
454+
end,
441455
}
456+
<
457+
458+
**Ignore Branches**
459+
460+
If you’d like to ignore certain branches from being saved as a session:
461+
462+
>lua
463+
{
464+
"olimorris/persisted.nvim",
465+
lazy = false,
466+
opts = {
467+
autostart = true,
468+
use_git_branch = true,
469+
},
470+
config = function(_, opts)
471+
local persisted = require("persisted")
472+
local utils = require("persisted.utils")
473+
local ignored_branches = {
474+
"feature_branch"
475+
}
442476

443-
if not utils.in_table(persisted.branch(), ignored_branches) then
444-
persisted.load()
445-
persisted.start()
446-
end
477+
persisted.setup(opts)
478+
if not utils.in_table(persisted.branch(), ignored_branches) then
479+
persisted.load()
480+
persisted.start()
481+
end
482+
end
483+
}
447484
<
448485

449486
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

0 commit comments

Comments
 (0)