summaryrefslogtreecommitdiff
path: root/lua/telescope/path.lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2020-12-09 16:58:22 +0100
committerGitHub <noreply@github.com>2020-12-09 16:58:22 +0100
commitc276db06e2981416995450a4198cef4b87170f6f (patch)
treeebd94e797892e197c7e30f082aaf93e28ba0d5c2 /lua/telescope/path.lua
parentd1c15dc2657c4bdec50f9cc7ad76c4dc182e8cc9 (diff)
Feat: Opt in vim buffers for previewers (#298)
Enable with: require('telescope').setup { defaults = { file_previewer = previewers.vim_buffer_cat.new, grep_previewer = previewers.vim_buffer_vimgrep.new, qflist_previewer = previewers.vim_buffer_qflist.new, } }
Diffstat (limited to 'lua/telescope/path.lua')
-rw-r--r--lua/telescope/path.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/lua/telescope/path.lua b/lua/telescope/path.lua
index 8fdbc71..cdfbc48 100644
--- a/lua/telescope/path.lua
+++ b/lua/telescope/path.lua
@@ -57,4 +57,45 @@ path.normalize = function(filepath, cwd)
return filepath
end
+path.read_last_line = function(filepath)
+ local fd = vim.loop.fs_open(filepath, "r", 438)
+ if fd == nil then return '' end
+ local stat = assert(vim.loop.fs_fstat(fd))
+ local data = ''
+ local index = stat.size - 2
+ while true do
+ local char = assert(vim.loop.fs_read(fd, 1, index))
+ if char == '\n' then break end
+ data = char .. data
+ index = index - 1
+ end
+ assert(vim.loop.fs_close(fd))
+ return data
+end
+
+path.read_file = function(filepath)
+ local fd = vim.loop.fs_open(filepath, "r", 438)
+ if fd == nil then return '' end
+ local stat = assert(vim.loop.fs_fstat(fd))
+ local data = assert(vim.loop.fs_read(fd, stat.size, 0))
+ assert(vim.loop.fs_close(fd))
+ return data
+end
+
+path.read_file_async = function(filepath, callback)
+ vim.loop.fs_open(filepath, "r", 438, function(err, fd)
+ assert(not err, err)
+ vim.loop.fs_fstat(fd, function(err, stat)
+ assert(not err, err)
+ vim.loop.fs_read(fd, stat.size, 0, function(err, data)
+ assert(not err, err)
+ vim.loop.fs_close(fd, function(err)
+ assert(not err, err)
+ return callback(data)
+ end)
+ end)
+ end)
+ end)
+end
+
return path