Skip to content

Commit

Permalink
add AutoSession.session_exists_for_cwd() function
Browse files Browse the repository at this point in the history
Add a function to understand if a session exists for the given current
working directory.

This is pretty helpful for start page plugins like mini.starter and
others.

By calling this function when nvim is opened to a workspace folder the
starter page can determine whether to show a 'restore session' option or
not.

Signed-off-by: ldelossa <louis.delos@gmail.com>
  • Loading branch information
ldelossa committed Apr 10, 2024
1 parent 64dc86e commit f0e90ae
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ local function auto_save_conditions_met()
return is_enabled() and auto_save() and not suppress_session() and is_allowed_dir() and not bypass_save_by_filetype()
end

-- Quickly checks if a session file exists for the current working directory.
-- This is useful for starter plugins which don't want to display 'restore session'
-- unless a session for the current working directory exists.
function AutoSession.session_exists_for_cwd()
session_file = get_session_file_name(vim.fn.getcwd())
return Lib.is_readable(session_file)
end

---AutoSaveSession
---Function called by auto_session to trigger auto_saving sessions, for example on VimExit events.
---@param sessions_dir? string the session directory to auto_save a session for. If empty this function will end up using the cwd to infer what session to save for.
Expand Down

0 comments on commit f0e90ae

Please sign in to comment.