From 03a16f99dc641a3b537d9d3f89cae1dc94f239b3 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Tue, 10 Jan 2023 21:39:11 -0600 Subject: fix(nvim): handle missing fortune/cowsay better --- nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'nvim/.config') 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", "", function() - sections.cowsay = with_spacer(cowsay(), 15) + sections.fortune = fortune() end, { desc = "next cowsay", buffer = buf }) end -- cgit v1.2.3-70-g09d2