From 041d8e92d17b28ac7e887cd8e334d88ef4e0f569 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 21 Dec 2022 21:26:48 +0900 Subject: neovim:uniquify: shorten path if there are other paths that are exactly the same --- .config/nvim/lua/tests/uniquify.lua | 1 + .config/nvim/lua/uniquify.lua | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.config/nvim/lua/tests/uniquify.lua b/.config/nvim/lua/tests/uniquify.lua index 9f58298..a8a190f 100644 --- a/.config/nvim/lua/tests/uniquify.lua +++ b/.config/nvim/lua/tests/uniquify.lua @@ -17,6 +17,7 @@ function M.test(t) {'foo/b/baz.txt', 'foo/bar/baz.txt', {'spam/bar/baz.txt'}}, {'foo/b/baz.txt', 'foo/bar/baz.txt', {'fiz/foo/bar/baz.txt', 'spam/bar/baz.txt'}}, {'fiz/f/b/baz.txt', 'fiz/foo/bar/baz.txt', {'foo/bar/baz.txt'}}, + {'foo.txt', 'bar/foo.txt', {'bar/foo.txt'}}, } for _, row in ipairs(test_cases) do diff --git a/.config/nvim/lua/uniquify.lua b/.config/nvim/lua/uniquify.lua index b9b9d32..c7f8482 100644 --- a/.config/nvim/lua/uniquify.lua +++ b/.config/nvim/lua/uniquify.lua @@ -8,6 +8,12 @@ local stricmp = vim.stricmp function M.uniquify(this_path, other_paths) + for i = 1, #other_paths do + if other_paths[i] == this_path then + table.remove(other_paths, i) + end + end + -- Split each path into slash-separated parts. for i = 1, #other_paths do other_paths[i] = split(other_paths[i], '[\\/]') -- cgit v1.2.3-70-g09d2