diff --git a/lua/telescope/_.lua b/lua/telescope/_.lua index e9b5e644da..7c6ed29275 100644 --- a/lua/telescope/_.lua +++ b/lua/telescope/_.lua @@ -5,6 +5,7 @@ local log = require "plenary.log" local async = require "plenary.async" local channel = require("plenary.async").control.channel +local utils = require "telescope.utils" local M = {} @@ -21,7 +22,7 @@ function AsyncJob.new(opts) self.stderr = opts.stderr or M.NullPipe() if opts.cwd and opts.cwd ~= "" then - self.uv_opts.cwd = vim.fn.expand(vim.fn.escape(opts.cwd, "$")) + self.uv_opts.cwd = utils.smart_path_expand(opts.cwd) -- this is a "illegal" hack for windows. E.g. If the git command returns `/` rather than `\` as delimiter, -- vim.fn.expand might just end up returning an empty string. Weird -- Because empty string is not allowed in libuv the job will not spawn. Solution is we just set it to opts.cwd diff --git a/lua/telescope/from_entry.lua b/lua/telescope/from_entry.lua index 4592d9bd16..4a176d7c37 100644 --- a/lua/telescope/from_entry.lua +++ b/lua/telescope/from_entry.lua @@ -7,6 +7,7 @@ This file is still WIP, so expect some changes if you're trying to consume these This will provide standard mechanism for accessing information from an entry. --============================================================================= ]] +local utils = require "telescope.utils" local from_entry = {} @@ -30,7 +31,7 @@ function from_entry.path(entry, validate, escape) -- TODO(conni2461): we are not going to return the expanded path because -- this would lead to cache misses in the perviewer. -- Requires overall refactoring in previewer interface - local expanded = vim.fn.expand(vim.fn.escape(path, "$?*[]")) + local expanded = utils.smart_path_expand(path) if (vim.fn.filereadable(expanded) + vim.fn.isdirectory(expanded)) == 0 then return end diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 058054a283..3114b81fbe 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -15,6 +15,10 @@ local get_status = require("telescope.state").get_status local utils = {} +utils.smart_path_expand = function(path) + return path:match "^[%%#<]" and vim.fn.expand(path) or path +end + utils.get_separator = function() return Path.path.sep end @@ -221,7 +225,7 @@ utils.transform_path = function(opts, path) if opts.cwd then cwd = opts.cwd if not vim.in_fast_event() then - cwd = vim.fn.expand(opts.cwd) + cwd = utils.smart_path_expand(opts.cwd) end else cwd = vim.loop.cwd()