Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new filename path option #1285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ sections = {
-- 2: Absolute path
-- 3: Absolute path, with tilde as the home directory
-- 4: Filename and parent dir, with tilde as the home directory
-- 5: Filename or filename and parent dir when there are duplicate filenames open, with tilde as the home directory

shorting_target = 40, -- Shortens path to leave 40 spaces in the window
-- for other components. (terrible name, any suggestions?)
Expand Down
20 changes: 20 additions & 0 deletions lua/lualine/components/filename.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ M.update_status = function(self)
elseif self.options.path == 4 then
-- filename and immediate parent
data = filename_and_parent(vim.fn.expand('%:p:~'), path_separator)
elseif self.options.path == 5 then
-- check for duplicate filenames in current buffers and add parent dir if a duplicate is found
local current_filename = vim.fn.expand('%:t')
local buffer_list = vim.fn.getbufinfo { buflisted = 1 }
local duplicate_found = false

for _, buf in ipairs(buffer_list) do
if buf.name ~= vim.fn.expand('%:p') and vim.fn.fnamemodify(buf.name, ':t') == current_filename then
duplicate_found = true
break
end
end

if duplicate_found then
-- add parent directory to distinguish duplicate filenames
local parent_dir = vim.fn.fnamemodify(vim.fn.expand('%:p:~'), ':h:t:~')
data = parent_dir .. path_separator .. current_filename
else
data = current_filename
end
else
-- just filename
data = vim.fn.expand('%:t')
Expand Down
Loading