Skip to content

Commit

Permalink
doc: add example guard for stdin (#71)
Browse files Browse the repository at this point in the history
* docs: add guard for stdin

* doc: merge StdinReadPre autocmd into other example

---------

Co-authored-by: Steven Arcangeli <[email protected]>
  • Loading branch information
melMass and stevearc authored Dec 24, 2024
1 parent 18f507c commit 271a6fd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ Load a dir-specific session when you open Neovim, save it when you exit.
```lua
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
-- Only load the session if nvim was started with no args
if vim.fn.argc(-1) == 0 then
-- Only load the session if nvim was started with no args and without reading from stdin
if vim.fn.argc(-1) == 0 and not vim.g.using_stdin then
-- Save these to a different directory, so our manual sessions don't get polluted
resession.load(vim.fn.getcwd(), { dir = "dirsession", silence_errors = true })
end
Expand All @@ -160,6 +160,12 @@ vim.api.nvim_create_autocmd("VimLeavePre", {
resession.save(vim.fn.getcwd(), { dir = "dirsession", notify = false })
end,
})
vim.api.nvim_create_autocmd('StdinReadPre', {
callback = function()
-- Store this for later
vim.g.using_stdin = true
end,
})
```

### Create one session per git branch
Expand Down

0 comments on commit 271a6fd

Please sign in to comment.