Skip to content

Instantly share code, notes, and snippets.

@cherryramatisdev
Created July 26, 2023 20:26
Show Gist options
  • Save cherryramatisdev/e94794970f45c8c634f03e392374e199 to your computer and use it in GitHub Desktop.
Save cherryramatisdev/e94794970f45c8c634f03e392374e199 to your computer and use it in GitHub Desktop.
local function getLastDirectory(fullPath)
-- Replace "file:////" with an empty string to remove it from the path
local cleanPath = string.gsub(fullPath, "file:////", "")
-- Separate the path using the directory separator "/"
local directories = {}
for directory in string.gmatch(cleanPath, "[^/]+") do
table.insert(directories, directory)
end
-- Return the last directory
if #directories > 0 then
return directories[#directories]
else
return nil
end
end
wezterm.on("format-tab-title", function(tab)
local pane = tab.active_pane
local cwd = pane.current_working_dir
local title = string.format("%s:%s", tab.tab_index + 1, getLastDirectory(cwd))
return {
{ Text = " " .. title .. " " },
}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment