Skip to content

Commit

Permalink
Merge pull request #90 from mistweaverco/fix/closest-file
Browse files Browse the repository at this point in the history
fix(fs): find nearest file
  • Loading branch information
gorillamoe authored Jul 31, 2024
2 parents c346a97 + 6caf08c commit b10b937
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lua/kulala/globals/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local FS = require("kulala.utils.fs")

local M = {}

M.VERSION = "2.8.0"
M.VERSION = "2.8.1"
M.UI_ID = "kulala://ui"
M.HEADERS_FILE = FS.get_plugin_tmp_dir() .. "/headers.txt"
M.BODY_FILE = FS.get_plugin_tmp_dir() .. "/body.txt"
Expand Down
16 changes: 10 additions & 6 deletions lua/kulala/utils/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ local M = {}
--- @return string|nil
--- @usage local p = fs.find_file_in_parent_dirs('Makefile')
M.find_file_in_parent_dirs = function(filename)
return vim.fs.find({filename}, {upward=true, limit=1})[1]
return vim.fs.find({ filename }, {
upward = true,
limit = 1,
path = vim.fn.expand("%:p:h"),
})[1]
end

-- Writes string to file
Expand All @@ -15,7 +19,7 @@ end
--- @return boolean
--- @usage local p = fs.write_file('Makefile', 'all: \n\t@echo "Hello World"')
M.write_file = function(filename, content)
local f = io.open(filename, 'w')
local f = io.open(filename, "w")
if f == nil then
return false
end
Expand Down Expand Up @@ -47,9 +51,9 @@ end
--- @return string
--- @usage local p = fs.get_plugin_tmp_dir()
M.get_plugin_tmp_dir = function()
local dir = vim.fn.stdpath('data') .. '/tmp/kulala'
local dir = vim.fn.stdpath("data") .. "/tmp/kulala"
if vim.fn.isdirectory(dir) == 0 then
vim.fn.mkdir(dir, 'p')
vim.fn.mkdir(dir, "p")
end
return dir
end
Expand All @@ -67,11 +71,11 @@ end
--- @return string
--- @usage local p = fs.read_file('Makefile')
M.read_file = function(filename)
local f = io.open(filename, 'r')
local f = io.open(filename, "r")
if f == nil then
return nil
end
local content = f:read('*a')
local content = f:read("*a")
f:close()
return content
end
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "kulala.nvim",
"version": "2.8.0"
"version": "2.8.1"
}

0 comments on commit b10b937

Please sign in to comment.