mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
snacks rice + new colorscheme
This commit is contained in:
parent
66d50e274e
commit
d998429cb8
15 changed files with 1068 additions and 427 deletions
|
|
@ -1,14 +1,14 @@
|
|||
local diff = require('mini.diff')
|
||||
local JJ = {
|
||||
local M = {
|
||||
cache = {},
|
||||
jj_cache = {},
|
||||
}
|
||||
|
||||
JJ.get_buf_realpath = function(buf_id)
|
||||
M.get_buf_realpath = function(buf_id)
|
||||
return vim.loop.fs_realpath(vim.api.nvim_buf_get_name(buf_id)) or ''
|
||||
end
|
||||
|
||||
JJ.jj_start_watching_tree_state = function(buf_id, path)
|
||||
M.jj_start_watching_tree_state = function(buf_id, path)
|
||||
local stdout = vim.loop.new_pipe()
|
||||
local args = { 'workspace', 'root', '--ignore-working-copy' }
|
||||
local spawn_opts = {
|
||||
|
|
@ -19,11 +19,11 @@ JJ.jj_start_watching_tree_state = function(buf_id, path)
|
|||
|
||||
local on_not_in_jj = vim.schedule_wrap(function()
|
||||
if not vim.api.nvim_buf_is_valid(buf_id) then
|
||||
JJ.cache[buf_id] = nil
|
||||
M.cache[buf_id] = nil
|
||||
return
|
||||
end
|
||||
diff.fail_attach(buf_id)
|
||||
JJ.jj_cache[buf_id] = {}
|
||||
M.jj_cache[buf_id] = {}
|
||||
end)
|
||||
|
||||
local process, stdout_feed = nil, {}
|
||||
|
|
@ -37,20 +37,20 @@ JJ.jj_start_watching_tree_state = function(buf_id, path)
|
|||
|
||||
-- Set up index watching
|
||||
local jj_dir_path = table.concat(stdout_feed, ''):gsub('\n+$', '') .. '/.jj/working_copy'
|
||||
JJ.jj_setup_tree_state_watch(buf_id, jj_dir_path)
|
||||
M.jj_setup_tree_state_watch(buf_id, jj_dir_path)
|
||||
|
||||
-- Set reference text immediately
|
||||
JJ.jj_set_ref_text(buf_id)
|
||||
M.jj_set_ref_text(buf_id)
|
||||
end
|
||||
|
||||
process = vim.loop.spawn('jj', spawn_opts, on_exit)
|
||||
JJ.jj_read_stream(stdout, stdout_feed)
|
||||
M.jj_read_stream(stdout, stdout_feed)
|
||||
end
|
||||
|
||||
JJ.jj_setup_tree_state_watch = function(buf_id, jj_dir_path)
|
||||
M.jj_setup_tree_state_watch = function(buf_id, jj_dir_path)
|
||||
local buf_fs_event, timer = vim.loop.new_fs_event(), vim.loop.new_timer()
|
||||
local buf_jj_set_ref_text = function()
|
||||
JJ.jj_set_ref_text(buf_id)
|
||||
M.jj_set_ref_text(buf_id)
|
||||
end
|
||||
|
||||
local watch_tree_state = function(_, filename, _)
|
||||
|
|
@ -63,11 +63,11 @@ JJ.jj_setup_tree_state_watch = function(buf_id, jj_dir_path)
|
|||
end
|
||||
buf_fs_event:start(jj_dir_path, { recursive = false }, watch_tree_state)
|
||||
|
||||
JJ.jj_invalidate_cache(JJ.jj_cache[buf_id])
|
||||
JJ.jj_cache[buf_id] = { fs_event = buf_fs_event, timer = timer }
|
||||
M.jj_invalidate_cache(M.jj_cache[buf_id])
|
||||
M.jj_cache[buf_id] = { fs_event = buf_fs_event, timer = timer }
|
||||
end
|
||||
|
||||
JJ.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
|
||||
M.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
|
||||
if not vim.api.nvim_buf_is_valid(buf_id) then
|
||||
return
|
||||
end
|
||||
|
|
@ -77,7 +77,7 @@ JJ.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
|
|||
end)
|
||||
|
||||
-- NOTE: Do not cache buffer's name to react to its possible rename
|
||||
local path = JJ.get_buf_realpath(buf_id)
|
||||
local path = M.get_buf_realpath(buf_id)
|
||||
if path == '' then
|
||||
return buf_set_ref_text {}
|
||||
end
|
||||
|
|
@ -105,10 +105,10 @@ JJ.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
|
|||
end
|
||||
|
||||
process = vim.loop.spawn('jj', spawn_opts, on_exit)
|
||||
JJ.jj_read_stream(stdout, stdout_feed)
|
||||
M.jj_read_stream(stdout, stdout_feed)
|
||||
end)
|
||||
|
||||
JJ.jj_read_stream = function(stream, feed)
|
||||
M.jj_read_stream = function(stream, feed)
|
||||
local callback = function(err, data)
|
||||
if data ~= nil then
|
||||
return table.insert(feed, data)
|
||||
|
|
@ -121,7 +121,7 @@ JJ.jj_read_stream = function(stream, feed)
|
|||
stream:read_start(callback)
|
||||
end
|
||||
|
||||
JJ.jj_invalidate_cache = function(cache)
|
||||
M.jj_invalidate_cache = function(cache)
|
||||
if cache == nil then
|
||||
return
|
||||
end
|
||||
|
|
@ -129,26 +129,26 @@ JJ.jj_invalidate_cache = function(cache)
|
|||
pcall(vim.loop.timer_stop, cache.timer)
|
||||
end
|
||||
|
||||
local jj = function()
|
||||
M.gen_source = function()
|
||||
local attach = function(buf_id)
|
||||
-- Try attaching to a buffer only once
|
||||
if JJ.jj_cache[buf_id] ~= nil then
|
||||
if M.jj_cache[buf_id] ~= nil then
|
||||
return false
|
||||
end
|
||||
-- - Possibly resolve symlinks to get data from the original repo
|
||||
local path = JJ.get_buf_realpath(buf_id)
|
||||
local path = M.get_buf_realpath(buf_id)
|
||||
if path == '' then
|
||||
return false
|
||||
end
|
||||
|
||||
JJ.jj_cache[buf_id] = {}
|
||||
JJ.jj_start_watching_tree_state(buf_id, path)
|
||||
M.jj_cache[buf_id] = {}
|
||||
M.jj_start_watching_tree_state(buf_id, path)
|
||||
end
|
||||
|
||||
local detach = function(buf_id)
|
||||
local cache = JJ.jj_cache[buf_id]
|
||||
JJ.jj_cache[buf_id] = nil
|
||||
JJ.jj_invalidate_cache(cache)
|
||||
local cache = M.jj_cache[buf_id]
|
||||
M.jj_cache[buf_id] = nil
|
||||
M.jj_invalidate_cache(cache)
|
||||
end
|
||||
|
||||
local apply_hunks = function(_, _)
|
||||
|
|
@ -162,4 +162,4 @@ local jj = function()
|
|||
apply_hunks = apply_hunks,
|
||||
}
|
||||
end
|
||||
return jj
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
local M = {}
|
||||
M.load = function()
|
||||
sessions = require('mini.sessions')
|
||||
|
||||
M.get_id = function()
|
||||
local jj_root = vim.system({ 'jj', 'workspace', 'root' }):wait()
|
||||
local sessions = require('mini.sessions')
|
||||
|
||||
if jj_root.code ~= 0 then
|
||||
return
|
||||
|
|
@ -19,29 +20,42 @@ M.load = function()
|
|||
'--no-graph',
|
||||
})
|
||||
:wait()
|
||||
local branch = vim.trim(string.gsub(result.stdout, '[\n*]', ''))
|
||||
local branch = vim.trim(string.gsub(result.stdout, '[\n*]', '')) -- trim newlines and unpushed indicator
|
||||
local root = vim.trim(string.gsub(jj_root.stdout, '\n', ''))
|
||||
local jj_sesh = string.gsub(string.format('jj:%s:%s', root, branch), '[./]', '-')
|
||||
if jj_sesh ~= '' then
|
||||
vim.opt.shadafile = vim.fn.stdpath('data') .. '/myshada/' .. jj_sesh .. '.shada'
|
||||
for name, _ in pairs(sessions.detected) do
|
||||
if name == jj_sesh then
|
||||
vim.ui.select({
|
||||
'No',
|
||||
'Yes',
|
||||
}, { prompt = 'Session found at ' .. jj_sesh .. ', load it?' }, function(c)
|
||||
if c == 'Yes' then
|
||||
-- load session (buffers, etc) as well as shada (marks)
|
||||
sessions.read(jj_sesh)
|
||||
vim.cmd('rshada')
|
||||
vim.notify('loaded jj session: ' .. jj_sesh)
|
||||
end
|
||||
end)
|
||||
return
|
||||
end
|
||||
local id = string.gsub(string.format('jj:%s:%s', root, branch), '[./]', '-') -- slugify
|
||||
return id
|
||||
end
|
||||
|
||||
M.check_exists = function(id)
|
||||
for name, _ in pairs(sessions.detected) do
|
||||
if name == id then
|
||||
return true
|
||||
end
|
||||
vim.cmd('wshada')
|
||||
sessions.write(jj_sesh)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
M.load = function()
|
||||
local id = M.get_id()
|
||||
if id == '' then
|
||||
return
|
||||
end
|
||||
vim.opt.shadafile = vim.fn.stdpath('data') .. '/myshada/' .. id .. '.shada'
|
||||
if M.check_exists(id) then
|
||||
vim.ui.select({
|
||||
'Yes',
|
||||
'No',
|
||||
}, { prompt = 'Session found at ' .. id .. ', load it?' }, function(c)
|
||||
if c == 'Yes' then
|
||||
-- load session (buffers, etc) as well as shada (marks)
|
||||
sessions.read(id)
|
||||
vim.cmd('rshada')
|
||||
vim.notify('loaded jj session: ' .. id)
|
||||
end
|
||||
end)
|
||||
else
|
||||
vim.cmd('wshada') -- create session if it did not exist
|
||||
sessions.write(id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
26
nvim/lua/plugins/lib/snacks.lua
Normal file
26
nvim/lua/plugins/lib/snacks.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
M = {}
|
||||
M.marks = function()
|
||||
return {
|
||||
finder = 'vim_marks',
|
||||
format = 'file',
|
||||
['local'] = false,
|
||||
global = true,
|
||||
actions = {
|
||||
markdel = function(picker)
|
||||
for _, item in ipairs(picker:selected()) do
|
||||
vim.cmd.delmarks { args = { item.label } }
|
||||
end
|
||||
vim.cmd('wshada')
|
||||
picker.list:set_selected()
|
||||
picker.list:set_target()
|
||||
picker:find()
|
||||
end,
|
||||
},
|
||||
win = {
|
||||
list = {
|
||||
keys = { ['dd'] = 'markdel' },
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
return M
|
||||
|
|
@ -67,6 +67,7 @@ function M.revs()
|
|||
Snacks.picker.util.cmd(cmd, function()
|
||||
Snacks.notify('Checking out revision: ' .. item.rev, { title = 'Snacks Picker' })
|
||||
vim.cmd.checktime()
|
||||
require('plugins.lib.session_jj').load()
|
||||
end, { cwd = item.cwd })
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue