aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/nvim/.config
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-01-10 21:39:11 -0600
committerToby Vincent <tobyv13@gmail.com>2023-01-10 21:39:11 -0600
commit03a16f99dc641a3b537d9d3f89cae1dc94f239b3 (patch)
treee9a3edea87f7a16fb63d0069041b87ebfcefbafe /nvim/.config
parent27e792899b70588b0924da797a74c13318f6cb82 (diff)
fix(nvim): handle missing fortune/cowsay better
Diffstat (limited to 'nvim/.config')
-rw-r--r--nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua25
1 files changed, 14 insertions, 11 deletions
diff --git a/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua b/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua
index cab3960..d637161 100644
--- a/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua
+++ b/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua
@@ -5,7 +5,7 @@ local dashboard = {}
local _index = {
header = 1,
lazy = 2,
- cowsay = 3,
+ fortune = 3,
}
---@type string[]
@@ -131,12 +131,16 @@ local function with_spacer(lines, count)
return spaced
end
-local function cowsay()
+local function fortune()
local Job = require("plenary.job")
- return Job:new({
- command = "cowsay",
- writer = Job:new({ command = "fortune", args = { "-s" } }),
- }):sync()
+ local job = Job:new({ command = "fortune", args = { "-s" } })
+
+ local ok, is_exe = pcall(vim.fn.executable, "cowsay")
+ if ok and 1 == is_exe then
+ job = Job:new({ command = "cowsay", writer = job })
+ end
+
+ return job:sync()
end
local augroup = vim.api.nvim_create_augroup("dashboard", { clear = true })
@@ -164,13 +168,12 @@ vim.api.nvim_create_autocmd("BufHidden", {
desc = "clear dashboard autocmds",
})
-local c_ok, c_exe = pcall(vim.fn.executable, "cowsay")
-local f_ok, f_exe = pcall(vim.fn.executable, "fortune")
-if c_ok and 1 == c_exe and f_ok and 1 == f_exe then
- sections.cowsay = with_spacer(cowsay(), 15)
+local ok, is_exe = pcall(vim.fn.executable, "fortune")
+if ok and 1 == is_exe then
+ sections.fortune = fortune()
vim.keymap.set("n", "<C-n>", function()
- sections.cowsay = with_spacer(cowsay(), 15)
+ sections.fortune = fortune()
end, { desc = "next cowsay", buffer = buf })
end