lualine.nvim icon indicating copy to clipboard operation
lualine.nvim copied to clipboard

feat: Add harpoon_files component

Open tamighi opened this issue 1 year ago • 2 comments

Description

Since I found that feature useful for having better view on marked files, I decided to share it with you. This pull request adds the harpoon_files component feature to the project. This feature shows the files marked by the ThePrimeagen/harpoon plugin, including inactives and active files. The code is inspired by the 'buffers' component, so most of it is duplicated and the logic is the same.

The on click feature is not yet implemented.

Changes Made

  • Added harpoon_files folder with harpoon_file.lua and init.lua in components folder.
  • Updated README.md.

How to use it

Simply use it as you would use other components

  ...
  sections = {
    lualine_a = { 'mode' },
    lualine_b = { 'harpoon_files' },
    lualine_c = { 'branch', 'diff', 'diagnostics' },
  },
  ...

Possible options (taken from buffers, see README):

show_filename_only = true,
hide_filename_extension = false, 
max_length = vim.o.columns * 2 / 3, 
use_mode_colors = false,
harpoon_files_color = {
        active = 'lualine_section_normal',     -- Color for active harpoon file.
        inactive = 'lualine_section_inactive', -- Color for inactive harpoon 
}

tamighi avatar Apr 17 '23 16:04 tamighi

+1 this is great! Harpoon solves a lot of annoyances with global marks, and this solves the issue of me forgetting what is marked with harpoon.

bryanvaz avatar Aug 02 '23 20:08 bryanvaz

+1 this is great! Harpoon solves a lot of annoyances with global marks, and this solves the issue of me forgetting what is marked with harpoon.

Hey, glad you like it ! If you would like to use it with the current version of lualine, here is a simple function implementation:

local hp_marks = require('harpoon.mark')
local devicons = require('nvim-web-devicons')

function Harpoon_files()
  local contents = {}

  for idx = 1, hp_marks.get_length() do
    local file_path = hp_marks.get_marked_file_name(idx)
    local file_name
    if file_path == "" then
      file_name = "(empty)"
    else
      file_name = vim.fn.fnamemodify(file_path, ':t')
    end
    local dev, _ = devicons.get_icon(file_name)

    local current_file_path = vim.fn.expand("%:f")

    local prev = ""
    if idx ~= 1 then
      prev = " "
    end
    local next = ""
    if idx < hp_marks.get_length() then
      next = " "
    end
    if file_path == current_file_path then
      contents[idx] = string.format("%%#lualine_b_normal#%s%s %s%s", prev, dev, file_name, next)
    else
      contents[idx] = string.format("%%#lualine_b_inactive#%s%s %s%s", prev, dev, file_name, next)
    end
  end

  return table.concat(contents)
end

lualine.setup({
  ...
  sections = {
    lualine_b = { { Harpoon_files } },
    ...
  },
})

tamighi avatar Aug 03 '23 04:08 tamighi