Skip to content

Commit

Permalink
fix: write nil should create file
Browse files Browse the repository at this point in the history
chore: tweak
  • Loading branch information
phanen committed Apr 21, 2024
1 parent ead1f53 commit 08404cd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/fzf-lua-overlay/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ M.create_notes = function(_, opts)
if #(vim.split(query, '.', { plain = true })) == 1 then path = path .. '.md' end
if not vim.uv.fs_stat(path) then
local u = require('fzf-lua-overlay.util')
local ok = u.write_file(path, 'a')
local ok = u.write_file(path, nil, 'w')
if not ok then return vim.notify(('fail to create file %s'):format(path)) end
end
vim.cmd.e(path)
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua-overlay/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
u.write_file = function(path, str, flag)
local fd = io.open(path, flag or 'w')
if not fd then return false end
fd:write(str)
if str then fd:write(str) end
fd:close()
return true
end
Expand All @@ -76,7 +76,7 @@ u.write_json = function(path, tbl)
end

u.gitroot = function(bufname)
bufname = bufname and bufname or vim.api.nvim_buf_get_name(0)
if not bufname then bufname = vim.api.nvim_buf_get_name(0) end
local path = vim.fs.dirname(bufname)
local root = vim.system { 'git', '-C', path, 'rev-parse', '--show-toplevel' }:wait().stdout
if root then
Expand Down

0 comments on commit 08404cd

Please sign in to comment.