AstroNvim / astroui

UI Configuration Engine built for AstroNvim
https://AstroNvim.com
GNU General Public License v3.0
19 stars 9 forks source link

Relativize path in separated_path to home #29

Closed Axlefublr closed 3 months ago

Axlefublr commented 3 months ago

📑 Description

It's very common to see $HOME as ~, to the point of it being weird when it's not presented as ~

So, this PR makes separated_path display the $HOME part of the path as ~, if possible.

ℹ Additional Information

Axlefublr commented 3 months ago

image

Here's an example of how this ends up looking. Here at the top left, I have the separated_path element (with a separator of /). This way, it just looks like a normal path.

Without this change, it would show ~ as home/username

Axlefublr commented 3 months ago

no clue how I'd configure this through path_func. I assume I'd have to change the implementation of unique_path, but I can't understand that code at all. Or do I somehow change path_func without relying on unique_path? Can you elaborate?

mehalter commented 3 months ago

when you call this function when building your own custom heirline configuration:

status.component.separated_path {
  max_depth = -1,
  separator = "/",
  path_func = function(self) return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(self.bufnr), ":~") end,
}
mehalter commented 3 months ago

the default usage of separated path using the unique_path for the path function actually doesn't make much sense to waste computation to calculate this because it would never come up. It only makes sense given a different path_func so it's better to leave it up to the user to handle that on their own. Hopefully that makes sense!