Skip to content

Commit 4b5364a

Browse files
GaetanLepagenix-infra-bot
authored andcommitted
plugins/persisted: init
1 parent e2f81c8 commit 4b5364a

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed

plugins/by-name/persisted/default.nix

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
lib,
3+
config,
4+
...
5+
}:
6+
let
7+
inherit (lib.nixvim) defaultNullOpts;
8+
inherit (lib) types;
9+
in
10+
lib.nixvim.neovim-plugin.mkNeovimPlugin {
11+
name = "persisted";
12+
originalName = "persisted.nvim";
13+
package = "persisted-nvim";
14+
15+
maintainers = [ lib.maintainers.GaetanLepage ];
16+
17+
extraOptions = {
18+
enableTelescope = lib.mkEnableOption "persisted-nvim telescope integration";
19+
};
20+
21+
extraConfig = cfg: {
22+
warnings = lib.optional (cfg.enableTelescope && (!config.plugins.telescope.enable)) ''
23+
Telescope support for `plugins.persisted` is enabled but the telescope plugin is not.
24+
'';
25+
26+
plugins.telescope.enabledExtensions = lib.mkIf cfg.enableTelescope [ "persisted" ];
27+
};
28+
29+
settingsOptions = {
30+
autostart = defaultNullOpts.mkBool true ''
31+
Whether to automatically start the plugin on load.
32+
'';
33+
34+
should_save =
35+
defaultNullOpts.mkRaw
36+
''
37+
function()
38+
return true
39+
end
40+
''
41+
''
42+
Function to determine if a session should be saved.
43+
44+
```lua
45+
@type fun(): boolean
46+
```
47+
'';
48+
49+
save_dir = defaultNullOpts.mkStr (lib.nixvim.literalLua "vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/')") ''
50+
Directory where session files are saved.
51+
'';
52+
53+
follow_cwd = defaultNullOpts.mkBool true ''
54+
Whether to change the session file to match any change in the cwd.
55+
'';
56+
57+
use_git_branch = defaultNullOpts.mkBool false ''
58+
Whether to include the git branch in the session file name.
59+
'';
60+
61+
autoload = defaultNullOpts.mkBool false ''
62+
Whether to automatically load the session for the cwd on Neovim startup.
63+
'';
64+
65+
on_autoload_no_session = defaultNullOpts.mkRaw "function() end" ''
66+
67+
Function to run when `autoload = true` but there is no session to load.
68+
69+
```lua
70+
@type fun(): any
71+
```
72+
'';
73+
74+
allowed_dirs = defaultNullOpts.mkListOf types.str [ ] ''
75+
List of dirs that the plugin will start and autoload from.
76+
'';
77+
78+
ignored_dirs = defaultNullOpts.mkListOf types.str [ ] ''
79+
List of dirs that are ignored for starting and autoloading.
80+
'';
81+
82+
telescope = {
83+
mappings =
84+
defaultNullOpts.mkAttrsOf types.str
85+
{
86+
copy_session = "<C-c>";
87+
change_branch = "<C-b>";
88+
delete_session = "<C-d>";
89+
}
90+
''
91+
Mappings for managing sessions in Telescope.
92+
'';
93+
94+
icons =
95+
defaultNullOpts.mkAttrsOf types.str
96+
{
97+
selected = " ";
98+
dir = " ";
99+
branch = " ";
100+
}
101+
''
102+
Icons displayed in the Telescope picker.
103+
'';
104+
};
105+
};
106+
107+
settingsExample = {
108+
use_git_branch = true;
109+
autoload = true;
110+
on_autoload_no_session.__raw = ''
111+
function()
112+
vim.notify("No existing session to load.")
113+
end
114+
'';
115+
};
116+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
empty = {
3+
plugins.persisted.enable = true;
4+
};
5+
6+
defaults = {
7+
plugins.persisted = {
8+
enable = true;
9+
10+
settings = {
11+
autostart = true;
12+
should_save.__raw = ''
13+
function()
14+
return true
15+
end
16+
'';
17+
save_dir.__raw = "vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/')";
18+
follow_cwd = true;
19+
use_git_branch = false;
20+
autoload = false;
21+
on_autoload_no_session.__raw = "function() end";
22+
allowed_dirs = [ ];
23+
ignored_dirs = [ ];
24+
telescope = {
25+
mappings = {
26+
copy_session = "<C-c>";
27+
change_branch = "<C-b>";
28+
delete_session = "<C-d>";
29+
};
30+
icons = {
31+
selected = " ";
32+
dir = " ";
33+
branch = " ";
34+
};
35+
};
36+
};
37+
};
38+
};
39+
40+
example = {
41+
plugins.gitlab = {
42+
enable = true;
43+
44+
settings = {
45+
use_git_branch = true;
46+
autoload = true;
47+
on_autoload_no_session.__raw = ''
48+
function()
49+
vim.notify("No existing session to load.")
50+
end
51+
'';
52+
should_save.__raw = ''
53+
function()
54+
-- Do not save session when the current cwd is git root
55+
local uv = vim.loop
56+
local cwd = uv.cwd()
57+
local git_dir = uv.fs_stat(cwd .. "/.git")
58+
if git_dir == nil then
59+
return false
60+
end
61+
62+
-- Check if the current buffer is a GIT COMMIT message buffer
63+
local current_buf = vim.api.nvim_get_current_buf()
64+
local buf_name = vim.api.nvim_buf_get_name(current_buf)
65+
local is_git_commit = buf_name:match("COMMIT_EDITMSG$") ~= nil
66+
if is_git_commit then
67+
return false
68+
end
69+
70+
if vim.fn.argc() > 0 then
71+
return false
72+
end
73+
74+
return true
75+
end
76+
'';
77+
};
78+
};
79+
};
80+
}

0 commit comments

Comments
 (0)