diff --git a/README.md b/README.md index 7b50ba5..5927304 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ require("telescope").setup { hidden = { file_browser = false, folder_browser = false }, respect_gitignore = vim.fn.executable "fd" == 1 no_ignore = false, + show_symlinks = false, follow_symlinks = false, browse_files = require("telescope._extensions.file_browser.finders").browse_files, browse_folders = require("telescope._extensions.file_browser.finders").browse_folders, diff --git a/lua/telescope/_extensions/file_browser/finders.lua b/lua/telescope/_extensions/file_browser/finders.lua index 6b5aba5..291ebe0 100644 --- a/lua/telescope/_extensions/file_browser/finders.lua +++ b/lua/telescope/_extensions/file_browser/finders.lua @@ -65,7 +65,10 @@ local function fd_file_args(opts) if opts.no_ignore then table.insert(args, "--no-ignore") end - if opts.follow_symlinks then + if opts.show_symlinks then + table.insert(args, "--type") + table.insert(args, "symlink") + elseif opts.follow_symlinks then table.insert(args, "--follow") end return args @@ -174,6 +177,7 @@ end ---@field hidden table|boolean: determines whether to show hidden files or not (default: `{ file_browser = false, folder_browser = false }`) ---@field respect_gitignore boolean: induces slow-down w/ plenary finder (default: false, true if `fd` available) ---@field no_ignore boolean: disable use of ignore files like .gitignore/.ignore/.fdignore (default: false, requires `fd`) +---@field show_symlinks boolean: show symbolic links, i.e. files and folders (default: false) ---@field follow_symlinks boolean: traverse symbolic links, i.e. files and folders (default: false, only works with `fd`) ---@field hide_parent_dir boolean: hide `../` in the file browser (default: false) ---@field dir_icon string: change the icon for a directory (default: ) @@ -204,6 +208,7 @@ fb_finders.finder = function(opts) auto_depth = vim.F.if_nil(opts.auto_depth, false), -- depth for file browser respect_gitignore = vim.F.if_nil(opts.respect_gitignore, has_fd), no_ignore = vim.F.if_nil(opts.no_ignore, false), + show_symlinks = vim.F.if_nil(opts.show_symlinks, false), follow_symlinks = vim.F.if_nil(opts.follow_symlinks, false), files = vim.F.if_nil(opts.files, true), -- file or folders mode grouped = vim.F.if_nil(opts.grouped, false), diff --git a/lua/telescope/_extensions/file_browser/make_entry.lua b/lua/telescope/_extensions/file_browser/make_entry.lua index b8cf898..ef300a3 100644 --- a/lua/telescope/_extensions/file_browser/make_entry.lua +++ b/lua/telescope/_extensions/file_browser/make_entry.lua @@ -159,6 +159,10 @@ local make_entry = function(opts) end end + if entry.lstat.type == "link" then + path_display = string.format("%s -> %s", path_display, utils.transform_path(opts, entry.realpath)) + end + local file_width = vim.F.if_nil(opts.file_width, math.max(15, total_file_width)) -- TODO maybe this can be dealt with more cleanly if #path_display > file_width then @@ -242,6 +246,11 @@ local make_entry = function(opts) return t.lstat end + if k == "realpath" then + t.realpath = vim.F.if_nil(vim.loop.fs_realpath(t.value)) + return t.realpath + end + return rawget(t, rawget({ value = 1 }, k)) end diff --git a/lua/telescope/_extensions/file_browser/picker.lua b/lua/telescope/_extensions/file_browser/picker.lua index 99f076b..c66f908 100644 --- a/lua/telescope/_extensions/file_browser/picker.lua +++ b/lua/telescope/_extensions/file_browser/picker.lua @@ -67,6 +67,7 @@ local fb_picker = {} ---@field hidden table|boolean: determines whether to show hidden files or not (default: `{ file_browser = false, folder_browser = false }`) ---@field respect_gitignore boolean: induces slow-down w/ plenary finder (default: false, true if `fd` available) ---@field no_ignore boolean: disable use of ignore files like .gitignore/.ignore/.fdignore (default: false, requires `fd`) +---@field show_symlinks boolean: show symbolic links, i.e. files and folders (default: false) ---@field follow_symlinks boolean: traverse symbolic links, i.e. files and folders (default: false, only works with `fd`) ---@field browse_files function: custom override for the file browser (default: |fb_finders.browse_files|) ---@field browse_folders function: custom override for the folder browser (default: |fb_finders.browse_folders|)