summaryrefslogtreecommitdiff
path: root/README.md
blob: 7a8a7572f4acf90e6547809a000aeb39f63558e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Lineage.nvim

Lineage is an incredibly simple lua statusline for neovim. It was written in ~330 LOC and is designed to be easy for people to modify and extend with their own components.

> [!CAUTION]
> This is my first Neovim plugin. The code is likely not as good as it could be and I probably missed several best practices.

## Installation

I use nix to manage my neovim plugins so I'm not sure how installing plugins works using package managers. I'll update this with instructions later if I have time.

## Example Configurations

The default layout is my daily driver, which is fairly unusual as far as statuslines go. Since I use the winbar to hold per-buffer information like the file name and diagnostics, I put things like the current working directory and the tab count in my statusline.

### Icons Enabled

To use the default layout with nerd-font icons enabled (must have a nerd font):

```lua
require("lineage.nvim").setup {
  use_icons = true
}
```

### Regular Configuration

A totally regular configuration:

> [!WARNING]
> The git branch and status components require the mini.git and mini.diff plugins, respectively.

```lua
local lineage = require("lineage.nvim")
local comp = lineage.components
lineage.setup {
  use_icons = true,
  components = function()
    return {
      comp.mode({before = " "}), -- Gap before the first component
      comp.git_branch(),
      comp.filename({shorten_percentage = 70}), -- Shorten if takes up more than 70% of the line (only works with filename and cwd).

      "%=", -- Variable length spacer

      comp.location()
    }
  end
}
```

### Default Configuration

You probably don't want to use this one.

```lua
local lineage = require("lineage.nvim")
local comp = lineage.components
lineage.setup {
  use_icons = false,
  gaps = "  ",
  components = function()
    return {
      comp.mode({before = " "}),
      comp.git_branch(),
      comp.cwd(),

      "%=",

      comp.session_name(),
      comp.markdown_word_count(),
      comp.tab_counter(),
      -- Neovide breaks progress component so add a spacer after location if neovide is present.
      comp.location({after = vim.g.neovide and " " or ""}),
      comp.progress({after = ""}),
    }
  end
}
```

## Do it Yourself

Because of how simple this plugin is, it's very easy to write your own components or customize existing ones. All the utilities that were used to create the default components are exposed in the module.

### Simple Custom Component

Here is a full configuration with a custom markdown word counter component.

```lua
local lineage = require("lineage.nvim")

-- Custom component function. It just needs to return a string.
local custom_markdown_word_count = function(args)
  -- Check for extra arguments
  args = args or {}

  -- Get text to insert before and after the component (unnecessary but sometimes useful)
  local before = args.before or ""
  local after = args.after or ""

  -- Return an empty string if we're not focused on a markdown file
  if vim.bo.filetype ~= "markdown" then
    return ""
  end

  -- Get the word count of the current file or the current visual selection, if there is one.
  local word_count = vim.fn.wordcount().visual_words or vim.fn.wordcount().words

  -- Set the nerd fonts icon if icons are enabled or just ascii text if they're not
  local icon = lineage.use_icons and "󱀽 " or "words: "

  -- Construct the string to be added to the line.
  return before..icon..word_count..after
end

local comp = lineage.components
lineage.setup {
  use_icons = true,
  components = function()
    return {
      comp.mode({before = " "}),
      comp.git_branch(),
      comp.filename(),

      "%=", -- Variable length spacer

      comp.location()
    }
  end
}
```

### Colors

Because this plugin was designed to be as simple as possible, it does not have its own themes. Instead, all colors are pulled from existing highlights, meaning that any neovim theme will work. To see how this works, you can look at the code for the mode component.

### Shortening

Certain components like cwd and filename will shorten themselves if they take up a certain percentage of the statusline. They take an option (similar to before and after) that defines what this percentage is. To see how this works, you can look at the code for the cwd and filename components.