Skip to content

Commit

Permalink
utils: update turnc_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jun 10, 2024
1 parent 11549b0 commit d7d7c03
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lua/nxvim/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@ local M = {}
---@param hl_group string|number
---@param val string|"bg"|"fg"
function M.get_hl(hl_group, val)
local api_get_hl = vim.api.nvim_get_hl_by_name

if type(hl_group) == "number" then api_get_hl = vim.api.nvim_get_hl_by_id end

if val == "fg" then
val = "foreground"
elseif val == "bg" then
val = "background"
end

local ok, hl = pcall(api_get_hl, hl_group, true)
local ok, hl = pcall(vim.api.nvim_get_hl, hl_group, true)
if not ok then return nil end

return hl[val]
end

---@class TruncConfig
---@field max_dirs number
---@field max_path_len number
---@field prefix string
---@field trunc_symbol string

---@type TruncConfig
local default_trunc_config = {
max_dirs = 3,
max_path_len = 2,
prefix = "", -- "󰘍" ""
trunc_symbol = "",
}

---@param input_path string
function M.truc_path(input_path)
---@param config? { max_dirs: number, max_path_len: number, prefix: string, trunc_symbol: string }
function M.truc_path(input_path, config)
local home_path = vim.fn.expand("$HOME")
if string.match(input_path, home_path) then input_path = input_path:gsub(home_path, "~") end

local cfg = {
max_dirs = 3,
max_path_len = 2,
prefix = "", -- "󰘍" ""
trunc_symbol = "",
}
local cfg = vim.tbl_deep_extend("keep", config or {}, default_trunc_config)

local path = vim.split(input_path, "/")
local res = path[1]
Expand Down

0 comments on commit d7d7c03

Please sign in to comment.