Replies: 3 comments 2 replies
-
Look at |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks @gegoune , I was able to write ( poorly ) a function that did what I was looking for. Here is the solution I came up with (I'm going to assume there are optimizations that can be done): function shorten_root_path(value)
local home = os.getenv("HOME")
local path = ""
local sep = "/"
local t = {}
for str in string.gmatch(value, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
local size = 0
for _ in pairs(t) do size = size + 1 end
local index = 0
if value:find(home, 1, true) == 1 then
local _, count = string.gsub(home, "/", "")
index = count + 1
path = "~"
end
for k, v in pairs(t) do
if k >= index then
if (path:len() == 0) then
path = string.sub(v, 1, 1)
elseif (v:len() == 1) then
path = path .. sep .. v
elseif (k == size) then
path = path .. sep .. v
else
path = path .. sep .. string.sub(v, 1, 1)
end
end
end
return path
end |
Beta Was this translation helpful? Give feedback.
1 reply
-
@madelaney I think this is something you're looking for: root_folder_label = function(path)
path = path:gsub(os.getenv("HOME"), "~", 1)
return path:gsub("([a-zA-Z])[a-z]+", "%1") .. path:gsub(".*[^a-zA-Z].?", "")
end, turns I honestly think this should become the standard. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It is possible to change the root path to a shortened format? For example if my full path is
~/work/gitlab.mldelaney.io/project_a/example-repo
, rather then displaying the full path could we display~/w/g/p/example-repo
?Beta Was this translation helpful? Give feedback.
All reactions