Created
July 26, 2023 20:26
-
-
Save cherryramatisdev/e94794970f45c8c634f03e392374e199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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