Skip to content

Commit

Permalink
feat: 직전의 session 을 저장하고 불러올 수 있도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
deptno committed Oct 4, 2023
1 parent 7b2e427 commit 1996f7c
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions lua/custom/configs/vim-startify.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
local PREVIOUS_SESSION_LINK_PATH = vim.fn.stdpath('data') .. '/previous_session'
local get_privous_session = function ()
local __LAST__ = '__LAST__'
local fn = vim.fn
local last_session_path = fn.stdpath('data') .. '/session/' .. __LAST__
local current_session = fn.resolve(last_session_path)

if vim.fs.basename(current_session )== last_session_path then
return print("There is no last_session_path")
end

return current_session
end
local create_previous_session_link = function()
local session = get_privous_session()

if session then
local source = '../' .. vim.fs.basename(session)

vim.fn.system('ln -fs ' .. source .. ' ' .. PREVIOUS_SESSION_LINK_PATH)
end
end
local switch_privous_session = function ()
local current_session = vim.fn.resolve(PREVIOUS_SESSION_LINK_PATH)

if vim.fn.filereadable(current_session) then
vim.cmd('SLoad ' .. vim.fs.basename(current_session))
end
end
local map = function (fn, tlb)
assert(type(fn) == "function", "fn: function")
assert(type(tlb) == "table", "tlb: table(list)")
Expand Down Expand Up @@ -25,7 +54,18 @@ local get_git_files = function ()
return ret
end

-- https://github.com/deptno/.config/blob/8bb421a122c30b172f3cd8ec9ac0f8894fe46bc5/.config/nvim/lua/user/startify.lua
-- @legacy https://github.com/deptno/.config/blob/8bb421a122c30b172f3cd8ec9ac0f8894fe46bc5/.config/nvim/lua/user/startify.lua
vim.g.startify_show_help = 1
vim.g.startify_show_help_delay = 1
vim.g.startify_show_help_delay_interval = 0.1
vim.g.startify_change_to_dir = 0
vim.g.change_to_vcs_root = 1
vim.g.startify_custom_header = {}
vim.g.startify_update_oldfiles = 1
vim.g.startify_session_persistence = 1
vim.g.startify_session_autoload = 1
vim.g.startify_enable_special = 0
-- vim.g.startify_session_before_save = { 'NvimTreeClose' }
vim.g.startify_bookmarks = {
{ bz = '~/.zshrc' },
{ bg = '~/.gitconfig' },
Expand All @@ -34,13 +74,7 @@ vim.g.startify_bookmarks = {
{ bt = '~/.tmux.conf' },
'~/.taskrc',
}
vim.g.startify_show_help = 1
vim.g.startify_show_help_delay = 1
vim.g.startify_show_help_delay_interval = 0.1
vim.g.startify_change_to_dir = 0
vim.g.change_to_vcs_root = 1
vim.g.startify_custom_header = {}
-- sessions wrapper 를 만들기 귀찮아서 처리
-- session list wrapper 를 만들기 귀찮아서 처리
vim.g.startify_custom_indices = {
'c.',
'cn',
Expand All @@ -52,22 +86,23 @@ vim.g.startify_custom_indices = {
'pz',
'wp',
'ww',
'll',
}
vim.g.switch_privous_session = switch_privous_session
vim.g.startify_commands = {
{ ll = { "previous session", "= vim.g.switch_privous_session()" }, },
}
vim.g.startify_lists = {
{ type = 'commands', header = { ' Commands' } },
{ type = 'sessions', header = { ' Sessions' } },
{ type = get_git_files, header = { ' 💻 Git files' } },
{ type = 'files', header = { ' 🕘 Recent ' } },
{ type = 'dir', header = { ' 📂 Current directory ' .. vim.fn.getcwd() } },
{ type = 'commands', header = { ' Commands' } },
{ type = 'bookmarks', header = { ' Bookmarks' } },
}

vim.api.nvim_create_autocmd("VimLeavePre", {
vim.api.nvim_create_autocmd("SessionLoadPost", {
group = vim.api.nvim_create_augroup("StartifyAutoSaveSession", { clear = true }),
callback = function()
vim.cmd("SSave! _latest")
end,
callback = create_previous_session_link,
})
vim.cmd [[
function! GetUniqueSessionName()
Expand Down

0 comments on commit 1996f7c

Please sign in to comment.