Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ require('telescope').extensions.smart_open.smart_open {

Limit the results to files under the current working directory. This is normally not needed because if you prefer this pattern of access, then the plugin will pick up on that over time regardless, to the point where files under `cwd` will be recommended above all others.

- `use_git_root_as_cwd` (default: `false`)

Use the root (based on .git) as the working directory.

- `filename_first` (default: `true`)

Format filename as "filename path/to/parent/directory" if `true` and "path/to/parent/directory/filename" if `false`.
Expand Down
8 changes: 6 additions & 2 deletions lua/telescope/_extensions/smart_open.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ local config = require("smart-open").config
local smart_open = function(opts)
opts = opts or {}

---@diagnostic disable-next-line: missing-parameter
opts.cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
if opts.use_git_root_as_cwd then
opts.cwd = vim.fn.expand(vim.fs.root(0, ".git") or vim.fn.getcwd())
else
---@diagnostic disable-next-line: missing-parameter
opts.cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
end
opts.current_buffer = vim.fn.bufnr("%") > 0 and vim.api.nvim_buf_get_name(vim.fn.bufnr("%")) or ""
opts.alternate_buffer = vim.fn.bufnr("#") > 0 and vim.api.nvim_buf_get_name(vim.fn.bufnr("#")) or ""
opts.filename_first = opts.filename_first == nil and true or opts.filename_first
Expand Down