Skip to content

Commit

Permalink
feat: alpha (#32)
Browse files Browse the repository at this point in the history
- feat(plugin): alpha init
- feat(plugin): setup alpha
  • Loading branch information
snelling-a authored May 5, 2023
2 parents 6725d1e + 3fa60dd commit 41d5ec6
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
|[folke/trouble.nvim](https://github.com/folke/trouble.nvim)|🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.|
|[freddiehaddad/feline.nvim](https://github.com/freddiehaddad/feline.nvim)|A minimal, stylish and customizable statusline / winbar for Neovim written in Lua|
|[github/copilot.vim](https://github.com/github/copilot.vim)|Neovim plugin for GitHub Copilot|
|[goolord/alpha-nvim](https://github.com/goolord/alpha-nvim)|a lua powered greeter like vim-startify / dashboard-nvim|
|[HiPhish/nvim-ts-rainbow2](https://github.com/HiPhish/nvim-ts-rainbow2)|Rainbow delimiters for Neovim through Tree-sitter|
|[hrsh7th/cmp-buffer](https://github.com/hrsh7th/cmp-buffer)|nvim-cmp source for buffer words|
|[hrsh7th/cmp-cmdline](https://github.com/hrsh7th/cmp-cmdline)|nvim-cmp source for vim's cmdline|
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
"siso",
"sqlls",
"stal",
"startify",
"stdpath",
"stylua",
"switchbuf",
Expand Down
1 change: 1 addition & 0 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Comment.nvim": { "branch": "master", "commit": "e1fe53117aab24c378d5e6deaad786789c360123" },
"LuaSnip": { "branch": "master", "commit": "a46ab6f8bce6bbddd8ce3e287e1a517c1f5e348e" },
"alpha-nvim": { "branch": "main", "commit": "447b821d22b0c1e80494638f84cb00ff696f4ef6" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "5af1bb7d722ef8a96658f01d6eb219c4cf746b32" },
"cmp-conventionalcommits": { "branch": "master", "commit": "a4dfacf0601130b7f8afa7c948d735c27802fb7f" },
Expand Down
37 changes: 27 additions & 10 deletions lua/config/session.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
local session_string = "sessions"
local session_file_name = "Session.vim"
local logger = require("config.util.logger")
local util = require("config.util")

local session_string = "sessions"
local session_file_name = "Session.vim"
local api = vim.api
local fn = vim.fn
local cmd = vim.cmd

local SessionGroup = api.nvim_create_augroup(session_string, { clear = true })
local M = {}

local is_file_readable = fn.filereadable(session_file_name) == 1 and 1

local function create_session()
cmd.mksession({ mods = { emsg_silent = true } })
if is_file_readable then
logger.info({ msg = "New session started", title = session_string })
end
end

function M.load_session()
if is_file_readable then
cmd.source({ args = { session_file_name }, mods = { silent = false, emsg_silent = true } })

logger.info({ msg = "Loaded session!", title = session_string })
else
create_session()
end
end

api.nvim_create_autocmd("VimEnter", {
group = SessionGroup,
nested = true,
Expand All @@ -19,15 +39,10 @@ api.nvim_create_autocmd("VimEnter", {
return
end

if fn.filereadable(session_file_name) == 1 then
cmd.source({ args = { session_file_name }, mods = { silent = false, emsg_silent = true } })

vim.defer_fn(function() logger.info({ msg = "Loaded session!", title = session_string }) end, 500)
if is_file_readable then
logger.info({ msg = "Session file found", title = session_string })
else
cmd.mksession({ mods = { emsg_silent = true } })
if fn.filereadable(session_file_name) == 1 then
vim.defer_fn(function() logger.info({ msg = "Loaded session!", title = session_string }) end, 500)
end
create_session()
end
end,
})
Expand All @@ -43,3 +58,5 @@ api.nvim_create_autocmd("VimLeavePre", {
cmd.mksession({ bang = true })
end,
})

return M
4 changes: 4 additions & 0 deletions lua/config/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ end
---@return _ boolean if `filetype` should have formatting
function Util.should_have_formatting(filetype) return not vim.tbl_contains(no_format, filetype) end

local vault_directory = os.getenv("NOTES") or os.getenv("HOME") .. "/notes"

Util.obsidian = { vault_directory = vault_directory, is_vault_directory = vim.fn.getcwd() == vault_directory }

return Util
133 changes: 133 additions & 0 deletions lua/plugins/alpha.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
local icons = require("config.ui.icons")

local is_obsidian = require("config.util").obsidian.is_vault_directory

---comment
---@param text? string @The text to display in the logo; defaults to "neovim"
---@return _ string @The header for alpha
local function get_header(text)
return " ▌║█║▌│║▌│║▌║▌█║ "
.. (text or "neovim")
.. " ▌│║▌║▌│║║▌█║▌║█ "
end

local quit_button = { shortcut = "q", val = icons.misc.exit .. " Quit", on_press = ":qa<CR>" }

local default_buttons = {
{ shortcut = "p", val = icons.misc.search .. " Find file", on_press = [[:lua require("fzf-lua").files() <CR>]] },
{ shortcut = "n", val = icons.file.newfile .. " New file", on_press = ":ene <BAR> startinsert <CR>" },
{
shortcut = "o",
val = icons.misc.files .. " Recent files",
on_press = [[:lua require("fzf-lua").oldfiles() <CR>]],
},
{
shortcut = "r",
val = icons.misc.search_text .. " Find text",
on_press = [[:lua require("fzf-lua").live_grep() <CR>]],
},
{
shortcut = "s",
val = icons.misc.restore .. " Restore Session",
on_press = [[:lua require("config.session").load_session() <cr>]],
},
{ shortcut = "l", val = icons.misc.lazy .. " Lazy", on_press = [[:lua vim.cmd.Lazy("update") <CR>]] },
{ shortcut = "m", val = icons.misc.tools .. " Mason", on_press = [[:lua vim.cmd.Mason() <CR>]] },
{ shortcut = "c", val = icons.misc.health .. " Check health", on_press = [[:lua vim.cmd.checkhealth() <CR>]] },
quit_button,
}

local obsidian_buttons = {
{
shortcut = "d",
val = icons.obsidian.today .. " Today's daily note",
on_press = [[:lua vim.cmd.ObsidianToday() <CR>]],
},
{
shortcut = "y",
val = icons.obsidian.yesterday .. " Yesterday's daily note",
on_press = [[:lua vim.cmd.ObsidianYesterday() <CR>]],
},
{
shortcut = "n",
val = icons.obsidian.new .. " New note",
on_press = [[:lua vim.cmd.ObsidianNew() <CR>]],
},
{
shortcut = "s",
val = icons.obsidian.search .. " Search daily notes",
on_press = [[:lua vim.cmd.ObsidianSearch() <CR>]],
},
{
shortcut = "c",
val = icons.obsidian.health .. " Check health",
on_press = [[:lua vim.cmd.ObsidianCheckHealth() <CR>]],
},
quit_button,
}

local M = { "goolord/alpha-nvim" }

M.event = "VimEnter"

function M.config(_, dashboard)
if vim.o.filetype == "lazy" then
vim.cmd.close()
vim.api.nvim_create_autocmd("User", {
pattern = "AlphaReady",
callback = function() require("lazy").show() end,
})
end

require("alpha").setup(dashboard.config)

vim.api.nvim_create_autocmd("User", {
pattern = "LazyVimStarted",
callback = function()
local version = "" .. vim.version().major .. "." .. vim.version().minor .. "." .. vim.version().patch
local stats = require("lazy").stats()
local startup_time = (math.floor(stats.startuptime * 100 + 0.5) / 100)
local total_plugins = stats.count .. " Plugins"
dashboard.section.footer.val = version .. "" .. total_plugins .. " 󰄉 " .. startup_time .. " ms"
pcall(vim.cmd.AlphaRedraw)
end,
})
end

function M.opts()
local dashboard = require("alpha.themes.dashboard")

local function get_buttons(button_set)
return vim.tbl_map(function(b)
local button = dashboard.button(b.shortcut, b.val, b.on_press)

button.opts.hl = "AlphaButtons"
button.opts.hl_shortcut = "AlphaShortcut"

return button
end, button_set or default_buttons)
end

local function get_content()
if is_obsidian then
return { header = get_header("obsidian"), buttons = get_buttons(obsidian_buttons) }
else
return { header = get_header(), buttons = get_buttons() }
end
end

local content = get_content()

dashboard.section.header.val = content.header

dashboard.section.buttons.val = content.buttons

dashboard.section.header.opts.hl = "AlphaHeader"
dashboard.section.buttons.opts.hl = "AlphaButtons"
dashboard.section.footer.opts.hl = "AlphaFooter"
dashboard.opts.layout[1].val = 8

return dashboard
end

return M
10 changes: 4 additions & 6 deletions lua/plugins/obsidian.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local obsidian = require("config.util").obsidian
local cmd = vim.cmd
local vault_directory = os.getenv("NOTES") or os.getenv("HOME") .. "/notes"

local function note_id_func(input)
local title = "Untitled"
Expand All @@ -12,16 +12,14 @@ end

local M = { "epwalsh/obsidian.nvim" }

M.is_vault_dir = vim.fn.getcwd() == vault_directory

M.dependencies = {
"nvim-lua/plenary.nvim",
"hrsh7th/nvim-cmp",
"ibhagwan/fzf-lua",
"nvim-treesitter/nvim-treesitter",
}

M.event = { "BufReadPre " .. vault_directory .. "/*" }
M.event = { "BufReadPre " .. obsidian.vault_directory .. "/*" }

M.ft = "markdown"

Expand All @@ -45,12 +43,12 @@ M.keys = {
},
}

M.lazy = not M.is_vault_dir
M.lazy = not obsidian.is_vault_directory

M.opts = {
completion = { nvim_cmp = true },
daily_notes = { folder = "daily-notes" },
dir = vault_directory,
dir = obsidian.vault_directory,
note_id_func = note_id_func,
open_app_foreground = true,
use_advanced_uri = true,
Expand Down

0 comments on commit 41d5ec6

Please sign in to comment.