persistence.nvim icon indicating copy to clipboard operation
persistence.nvim copied to clipboard

Allow session management to have a delayed start.

Open mahlonsmith opened this issue 2 years ago • 1 comments

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.

  • I use nvim for all sorts of sysadmin stuff, I don't need session files getting littered around unless I'm actually in a project that warrants it -- I want control over when to start and stop the management
  • I'd like to have a way to ask the plugin if it's currently active or not (a cleaner way might be to just check for the existence of the 'persistence' augroup, but I didn't find any methods to do that.)
  • Similarly, I'd like to ask the plugin if a session file is present for some basic boolean stuff.

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.

mahlonsmith avatar Aug 17 '23 04:08 mahlonsmith

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

github-actions[bot] avatar Jul 06 '24 01:07 github-actions[bot]

require("persistence").active()

folke avatar Jul 06 '24 19:07 folke