feat: add utility for fetching buffer directory (#902)

This commit is contained in:
Logan Connolly
2021-09-01 16:52:45 +02:00
committed by GitHub
parent 4d691fdc23
commit b0c04c62b5
2 changed files with 10 additions and 3 deletions

View File

@@ -66,8 +66,9 @@ local builtin = {}
-- --
-- --
--- Search for a string in your current working directory and get results live as you type (respecting .gitignore) --- Search for a string and get results live as you type (respecting .gitignore)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: directory path to search from (default is cwd, use utils.buffer_dir() to search relative to open buffer)
---@field grep_open_files boolean: if true, restrict search to open files only, mutually exclusive with `search_dirs` ---@field grep_open_files boolean: if true, restrict search to open files only, mutually exclusive with `search_dirs`
---@field search_dirs table: directory/directories to search in, mutually exclusive with `grep_open_files` ---@field search_dirs table: directory/directories to search in, mutually exclusive with `grep_open_files`
---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on
@@ -75,14 +76,16 @@ builtin.live_grep = require("telescope.builtin.files").live_grep
--- Searches for the string under your cursor in your current working directory --- Searches for the string under your cursor in your current working directory
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: directory path to search from (default is cwd, use utils.buffer_dir() to search relative to open buffer)
---@field search string: the query to search ---@field search string: the query to search
---@field search_dirs table: directory/directories to search in ---@field search_dirs table: directory/directories to search in
---@field use_regex boolean: if true, special characters won't be escaped, allows for using regex (default is false) ---@field use_regex boolean: if true, special characters won't be escaped, allows for using regex (default is false)
---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on ---@field additional_args function: function(opts) which returns a table of additional arguments to be passed on
builtin.grep_string = require("telescope.builtin.files").grep_string builtin.grep_string = require("telescope.builtin.files").grep_string
--- Lists files in your current working directory, respects .gitignore --- Search for files (respecting .gitignore)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: directory path to search from (default is cwd, use utils.buffer_dir() to search relative to open buffer)
---@field find_command table: command line arguments for `find_files` to use for the search, overrides default config ---@field find_command table: command line arguments for `find_files` to use for the search, overrides default config
---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command) ---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command)
---@field hidden boolean: determines whether to show hidden files or not (default is false) ---@field hidden boolean: determines whether to show hidden files or not (default is false)
@@ -102,7 +105,7 @@ builtin.fd = builtin.find_files
--- create the file `init.lua` inside of `lua/telescope` and will create the necessary folders (similar to how --- create the file `init.lua` inside of `lua/telescope` and will create the necessary folders (similar to how
--- `mkdir -p` would work) if they do not already exist --- `mkdir -p` would work) if they do not already exist
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: directory path to browse (default is cwd) ---@field cwd string: directory path to browse (default is cwd, use utils.buffer_dir() to browse relative to open buffer)
---@field depth number: file tree depth to display (default is 1) ---@field depth number: file tree depth to display (default is 1)
---@field dir_icon string: change the icon for a directory. default:  ---@field dir_icon string: change the icon for a directory. default: 
---@field hidden boolean: determines whether to show hidden files or not (default is false) ---@field hidden boolean: determines whether to show hidden files or not (default is false)

View File

@@ -414,6 +414,10 @@ function utils.data_directory()
return Path:new({ base_directory, "data" }):absolute() .. Path.path.sep return Path:new({ base_directory, "data" }):absolute() .. Path.path.sep
end end
function utils.buffer_dir()
return vim.fn.expand('%:p:h')
end
function utils.display_termcodes(str) function utils.display_termcodes(str)
return str:gsub(string.char(9), "<TAB>"):gsub("", "<C-F>"):gsub(" ", "<Space>") return str:gsub(string.char(9), "<TAB>"):gsub("", "<C-F>"):gsub(" ", "<Space>")
end end