Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why was default-path removed? Is there another way to achieve it? #2991

Closed
brandoncc opened this issue Dec 1, 2021 · 8 comments
Closed

Why was default-path removed? Is there another way to achieve it? #2991

brandoncc opened this issue Dec 1, 2021 · 8 comments

Comments

@brandoncc
Copy link

First, thank you for this wonderful tool!

I created a plugin for neovim that manages processes based on my current git worktree, which changes my working directory. This is a perfect use case for default-path, but it seems that was removed. Is there another way to do it? If found this, but that looks like a terrible way to have to solve this!

Please tell me there is a better way to tell tmux I want the new-window command to use a specific path without having to pass the -c flag.

For further information, I would like to change the "working directory" of the pane where neovim is running while neovim is still running. Then if I execute new-window, I need the new window to also be in the new working directory.

The "not so fun" solution I have come up is to set a session variable from my neovim plugin which can then be used in a tmux binding with the -c flag on neww... but I am hoping there is a better way.

Thanks again.

@nicm
Copy link
Member

nicm commented Dec 1, 2021

If you want tmux to use the current working directory from an already-running pane you can use pane_current_path, or have the application set pane_path with the escape sequence and use it:

neww -c '#{pane_current_path}'

If you want to set the working directory explicitly with an option you can use a user option and set that to where you want the path to be:

set -g @p /tmp
neww -c '#{@p}'

@bew
Copy link

bew commented Dec 1, 2021

You could also use attach-session -c "#{pane_current_path}" once to set the default path for windows for the current session.

@brandoncc
Copy link
Author

Thanks @nicm, I did devise a system like that which works:

if #vim.fn.system('printenv TMUX') > 0 then
  vim.fn.system('tmux set-option @default-path "' .. vim.fn.getcwd() .. '"')
end
# @default-path gets set in git-worktree.nvim switch callback
if-shell -b '[ -n `tmux show-option -v @default-path` ]' " \
    bind-key c new-window -c '#{@default-path}'; \
    bind-key c new-window -c '#{pane_current_path}'"

This workaround is working okay, although I don't love it.


Thanks @bew, that is actually the hack that is used in the script I linked.

@bew
Copy link

bew commented Dec 1, 2021

Thanks @bew, that is actually the hack that is used in the script I linked.

That script seems to do a lot for this..
I just do that command, it works well on 3.x:
https://github.com/bew/dotfiles/blob/ad8851bf565ab2/tmux/mappings.conf#L170-L171


For your vim config, you should be able to simply do:

if vim.env.TMUX then
  vim.fn.system('tmux attach-session -c "' .. vim.fn.getcwd() .. '"')
end

no?

@nicm
Copy link
Member

nicm commented Dec 1, 2021

You could do -c '#{?@default-path,#{@default-path},#{pane_current_path}}' instead of if-shell, or use if -F.

@brandoncc
Copy link
Author

Thanks @bew, that is actually the hack that is used in the script I linked.

That script seems to do a lot for this.. I just do that command, it works well on 3.x: https://github.com/bew/dotfiles/blob/ad8851bf565ab2/tmux/mappings.conf#L170-L171

For your vim config, you should be able to simply do:

if vim.env.TMUX then
  vim.fn.system('tmux attach-session -c "' .. vim.fn.getcwd() .. '"')
end

no?

That worked perfectly @bew, thank you! I think I had created my custom binding before trying this the first time so it was using current_pane_path and making me think it didn't work.

@brandoncc
Copy link
Author

You could do -c '#{?@default-path,#{@default-path},#{pane_current_path}}' instead of if-shell, or use if -F.

Thank you, I actually wondered about doing that, but I'm just learning how to use the format strings.

@github-actions
Copy link

github-actions bot commented Jan 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants