From 271a6fd7afa90142be59fca3a5c3b9865e40e6b9 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Tue, 24 Dec 2024 05:27:48 +0100 Subject: [PATCH] doc: add example guard for stdin (#71) * docs: add guard for stdin * doc: merge StdinReadPre autocmd into other example --------- Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com> --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 316f526..36b7d34 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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