From 2f02c47ef07a7050842a6a0788271afd3ede425e Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 13 Aug 2022 01:25:43 +0200 Subject: [PATCH] nvim: snippets: don't fail if name/email not found --- .config/nvim/lua/my/functions.lua | 4 ++-- .config/nvim/snippets/cpp.lua | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/my/functions.lua b/.config/nvim/lua/my/functions.lua index a8fae99..ab7a481 100644 --- a/.config/nvim/lua/my/functions.lua +++ b/.config/nvim/lua/my/functions.lua @@ -101,8 +101,8 @@ end function MY_shell_capture(command) local handle = io.popen(command) - if not handle then return '' end - local result = handle:read() or '' + if not handle then return nil end + local result = handle:read() or nil handle:close() return result end diff --git a/.config/nvim/snippets/cpp.lua b/.config/nvim/snippets/cpp.lua index f4df380..5dfcef7 100644 --- a/.config/nvim/snippets/cpp.lua +++ b/.config/nvim/snippets/cpp.lua @@ -61,9 +61,11 @@ return { end), name = f(function() return MY_shell_capture('git config user.name') + or 'INSERT_NAME' end), email = f(function() return MY_shell_capture('git config user.email') + or 'INSERT_EMAIL' end), cursor = i() }) @@ -85,9 +87,11 @@ return { end), name = f(function() return MY_shell_capture('git config user.name') + or 'INSERT_NAME' end), email = f(function() return MY_shell_capture('git config user.email') + or 'INSERT_EMAIL' end), cursor = i() })