folke / persistence.nvim

💾 Simple session management for Neovim
Apache License 2.0
591 stars 26 forks source link

Allow session management to have a delayed start. #30

Closed mahlonsmith closed 2 weeks ago

mahlonsmith commented 11 months ago

I'm really enjoying the simplicity of persistence, but coming from Obsession, there's a few things I was wanting, and I think this patch addresses them all.

With this patch, I can integrate things with lualine,

local function sessionRunning()
    if require( 'persistence' ).running then
        return ''
    else
        return ''
    end
end

... dashboard,

shortcut = {
    {
        desc = '↪️ Restore Session ',
        action = function()
            persistence = require( 'persistence' )
            if persistence.has_session() then
                persistence.load()
            else
                print "No session for this directory."
            end
        end,
        key = 's',
    },

and have a global "on/off" switch for only starting up a session when I want:

require( 'persistence' ).setup({
    auto_start = false
})

-- Toggle session tracking for current directory.
--
vim.keymap.set( '', '<F8>', function()
    local persistence = require( 'persistence' )
    if persistence.running then
        persistence.stop()
        print "Disabled session tracking."
    else
        persistence.start()
        print "Enabled session tracking."
    end
end, { desc = "Toggle session tracking" })

This also indirectly fixes stuff like #14 as a possible alternative option.

Default behavior is exactly as-is, this shouldn't change anything for existing installations.

github-actions[bot] commented 3 weeks ago

This PR is stale because it has been open 60 days with no activity.

folke commented 2 weeks ago

require("persistence").active()