Created
August 4, 2024 04:50
-
-
Save dtanphat9388/b1102afcf5ac9da9688a43a625f29f46 to your computer and use it in GitHub Desktop.
auto set tmux window with last part of basedir
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
-- [[ 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