Skip to content

Instantly share code, notes, and snippets.

@dtanphat9388
Created August 4, 2024 04:50
Show Gist options
  • Save dtanphat9388/b1102afcf5ac9da9688a43a625f29f46 to your computer and use it in GitHub Desktop.
Save dtanphat9388/b1102afcf5ac9da9688a43a625f29f46 to your computer and use it in GitHub Desktop.
auto set tmux window with last part of basedir
-- [[ set tmux window name by workspace ]]
local vimenter_group = vim.api.nvim_create_augroup("UserVimEnter", { clear = true })
vim.api.nvim_create_autocmd("VimEnter", {
group = vimenter_group,
callback = function()
local is_term_tmux = vim.env.TERM_PROGRAM == "tmux"
if not is_term_tmux then return end
local function get_last_directory(path)
path = path:gsub("[/\\]+$", "") -- Remove trailing slashes
return path:match("([^/\\]+)$") -- Capture the last directory name
end
local workspace_path = vim.fn.getcwd()
local workspace_name = get_last_directory(workspace_path)
local cmd = ("tmux rename-window %s"):format(workspace_name)
vim.fn.system(cmd)
end,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment