diff options
| author | Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> | 2021-07-16 17:41:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-16 17:41:39 +0100 |
| commit | 1866265feaebda2b615fadaa9230ec45958dd210 (patch) | |
| tree | a3e7663b4f0f9fa00a3bc4d410063d8e914fa91b /lua/telescope/utils.lua | |
| parent | 138697980b68ce7d4f0661c752691ffe5dbb72b0 (diff) | |
feat: Add length option for `shorten_path` (#886)
* feat: add `shorten_len` option for path shortening
- adds option to configure the length of shortened parts of filenames
- only affects paths when "shorten" is in `path_display`
* chore: revert rebase for `path.lua` to 876bed9
* refactor: replace `shorten_len` with the `shorten` key in `path_display`
- also deprecates `utils.path_shorten` and passes straight to `plenary`s `Path:shorten`
* feat: allow `path_display` to handle table keys, as well as strings
Diffstat (limited to 'lua/telescope/utils.lua')
| -rw-r--r-- | lua/telescope/utils.lua | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 9238ab7..6e35b81 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -3,6 +3,8 @@ local has_devicons, devicons = pcall(require, 'nvim-web-devicons') local Path = require('plenary.path') local Job = require('plenary.job') +local log = require('telescope.log') + local utils = {} utils.get_separator = function() @@ -251,8 +253,9 @@ utils.diagnostics_to_tbl = function(opts) return items end -utils.path_shorten = function(file) - return Path:new(file):shorten() +utils.path_shorten = function(filename,len) + log.warn("`utils.path_shorten` is deprecated. Use `require('plenary.path').shorten`.") + return Path:new(filename):shorten(len) end utils.path_tail = (function() @@ -268,7 +271,7 @@ utils.is_path_hidden = function(opts, path_display) path_display = path_display or utils.get_default(opts.path_display, require('telescope.config').values.path_display) return path_display == nil or path_display == "hidden" or - type(path_display) ~= "table" or vim.tbl_contains(path_display, "hidden") + type(path_display) ~= "table" or vim.tbl_contains(path_display, "hidden") or path_display.hidden end utils.transform_path = function(opts, path) @@ -284,10 +287,10 @@ utils.transform_path = function(opts, path) return '' end - if vim.tbl_contains(path_display, "tail") then + if vim.tbl_contains(path_display, "tail") or path_display.tail then transformed_path = utils.path_tail(transformed_path) else - if not vim.tbl_contains(path_display, "absolute") then + if not vim.tbl_contains(path_display, "absolute") or path_display.absolute == false then local cwd if opts.cwd then cwd = opts.cwd @@ -300,8 +303,8 @@ utils.transform_path = function(opts, path) transformed_path = Path:new(transformed_path):make_relative(cwd) end - if vim.tbl_contains(path_display, "shorten") then - transformed_path = Path:new(transformed_path):shorten() + if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then + transformed_path = Path:new(transformed_path):shorten(path_display["shorten"]) end end @@ -439,7 +442,7 @@ utils.transform_devicons = (function() end local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true }) - local icon_display = (icon or ' ') .. ' ' .. display + local icon_display = (icon or ' ') .. ' ' .. (display or '') if conf.color_devicons then return icon_display, icon_highlight |
