feat: add global var for if session exists in cwd
parent
d90f9adb04
commit
0ea44f1586
19
README.md
19
README.md
|
|
@ -101,7 +101,7 @@ require('telescope').setup({
|
||||||
|
|
||||||
## :rocket: Usage
|
## :rocket: Usage
|
||||||
|
|
||||||
**Default commands**
|
### Commands
|
||||||
|
|
||||||
The plugin comes with a number of commands:
|
The plugin comes with a number of commands:
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ The plugin comes with a number of commands:
|
||||||
- `:SessionLoadFromFile` - Load a session from a given path
|
- `:SessionLoadFromFile` - Load a session from a given path
|
||||||
- `:SessionDelete` - Delete the current session
|
- `:SessionDelete` - Delete the current session
|
||||||
|
|
||||||
**Telescope**
|
### Telescope extension
|
||||||
|
|
||||||
The Telescope extension may be opened via `:Telescope persisted`.
|
The Telescope extension may be opened via `:Telescope persisted`.
|
||||||
|
|
||||||
|
|
@ -123,12 +123,13 @@ Once opened, the available keymaps are:
|
||||||
- `<CR>` - Source the session file
|
- `<CR>` - Source the session file
|
||||||
- `<C-d>` - Delete the session file
|
- `<C-d>` - Delete the session file
|
||||||
|
|
||||||
**Global variables**
|
### Global variables
|
||||||
|
|
||||||
The plugin sets global variables which can be utilised in your configuration:
|
The plugin sets global variables which can be utilised in your configuration:
|
||||||
|
|
||||||
- `vim.g.persisting` - This is set to `true` when a session is started and `false` when a session is stopped
|
- `vim.g.persisting` - (bool) Determines if the plugin is active for the current session
|
||||||
- `vim.g.persisted_loaded_session` - The file path to the currently loaded session
|
- `vim.g.persisted_exists` - (bool) Determines if a session exists for the current working directory
|
||||||
|
- `vim.g.persisted_loaded_session` - (string) The file path to the current session
|
||||||
|
|
||||||
## :wrench: Configuration
|
## :wrench: Configuration
|
||||||
|
|
||||||
|
|
@ -349,6 +350,14 @@ The session data available differs depending on the events that are hooked into.
|
||||||
|
|
||||||
The plugin contains an extension for [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) which allows the user to list all of the saved session files and source them via `:Telescope persisted`.
|
The plugin contains an extension for [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) which allows the user to list all of the saved session files and source them via `:Telescope persisted`.
|
||||||
|
|
||||||
|
### Global variables
|
||||||
|
|
||||||
|
The plugin makes a number of global variables available for users to hook into during the lifecycle of their Neovim session:
|
||||||
|
|
||||||
|
- `vim.g.persisting` - (bool) Determines if the plugin is active for the current session
|
||||||
|
- `vim.g.persisted_exists` - (bool) Determines if a session exists for the current working directory
|
||||||
|
- `vim.g.persisted_loaded_session` - (string) The name of the active session
|
||||||
|
|
||||||
## :page_with_curl: License
|
## :page_with_curl: License
|
||||||
|
|
||||||
[MIT](https://github.com/olimorris/persisted.nvim/blob/main/LICENSE)
|
[MIT](https://github.com/olimorris/persisted.nvim/blob/main/LICENSE)
|
||||||
|
|
|
||||||
|
|
@ -75,12 +75,22 @@ local function get_current()
|
||||||
return config.options.save_dir .. name .. M.get_branch() .. ".vim"
|
return config.options.save_dir .. name .. M.get_branch() .. ".vim"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Determine if a session for the current wording directory, exists
|
||||||
|
---@return boolean
|
||||||
|
function M.session_exists()
|
||||||
|
return vim.fn.filereadable(get_current()) ~= 0
|
||||||
|
end
|
||||||
|
|
||||||
---Setup the plugin
|
---Setup the plugin
|
||||||
---@param opts? table
|
---@param opts? table
|
||||||
---@return nil
|
---@return nil
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
config.setup(opts)
|
config.setup(opts)
|
||||||
|
|
||||||
|
if M.session_exists() then
|
||||||
|
vim.g.persisted_exists = true
|
||||||
|
end
|
||||||
|
|
||||||
if
|
if
|
||||||
config.options.autosave
|
config.options.autosave
|
||||||
and (allow_dir() and not ignore_dir() and vim.g.persisting == nil)
|
and (allow_dir() and not ignore_dir() and vim.g.persisting == nil)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue