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

Feature request: default working directory of new tmux splits to worktree repo #116

Open
mattgallagher92 opened this issue Aug 12, 2024 · 4 comments

Comments

@mattgallagher92
Copy link

When working with a bare Git repo and worktrees, tms opens a new window for each worktree. The working directory for the pane in each of those windows is the worktree directory. When splitting the window, the working directory for the new pane is the directory containing the bare repo (usually the parent of the worktree directory), not the worktree directory itself.

It'd be great if tms configured the tmux window so that a new pane's working directory is the worktree directory.

P.S. I'm a tmux noob, so not sure whether that's even possible 😅
P.P.S. Thanks for tms, it's great!

@junglerobba
Copy link
Contributor

junglerobba commented Aug 13, 2024

tmux's split-window command has the -c option with which you can define the starting directory of the new split. If you use for example (copied from my config, mind the different keys)

bind -r v split-window -h -c "#{pane_current_path}"
bind -r s split-window -v -c "#{pane_current_path}"

you can make all splits inside a window open in the same directory.

@mattgallagher92 mattgallagher92 changed the title Feature requrest: default working directory of new tmux splits to worktree repo Feature request: default working directory of new tmux splits to worktree repo Aug 14, 2024
@mattgallagher92
Copy link
Author

Thanks @junglerobba, that works great!

I'll leave this issue open for now in case it seems like sensible default behaviour, but I'm happy for a maintainer to close it if not.

@OscarCreator
Copy link

I have the same problem/feature request. I usually have bare repos with many different worktrees and would like to be able to choose the worktree in the search list directly. If you don't want this as default behaviour this could be an --show-worktrees option or something. For example:

/home/user/projects/a/worktree_1
/home/user/projects/a/worktree_2
/home/user/projects/b

Then you would directly open the specific worktree and have the root folder for the tmux session be to the worktree you decided to work on.

@JulianNymark
Copy link

Then you would directly open the specific worktree and have the root folder for the tmux session be to the worktree you decided to work on.

I really like this idea!

I initially thought I wanted something adjacent to this, but this seems to be even better! 🤩 (I initially thought I wanted the ability to set the root folder for the tmux session to be a specific directory relative to the location of the bare repo root. Since I want to organize the structure of worktrees a particular way). To have a tmux session per worktree however seems much cleaner, and circumvents the need for such a feature.

It would then need to include the project as well in the session switcher, since I'd usually want similar worktrees (eg. main) in multiple projects.

eg. filtering for main:

projectA/main
projectA/feature-main-widget
projectB/main
projectC/main

also, it seems like tmux-sessionizer creates a main worktree automatically upon switching?. Since I wanted to follow the structure of something like https://morgan.cugerone.com/blog/how-to-use-git-worktree-and-in-a-clean-way/. Then I had to pre-empt this feature by creating my own main ahead of time (in the specific location I want).

Here's also two aliases I have to follow the same structuring described in the link above.

# new git project setup (using bare repos & worktrees)
# USAGE: repo githubusername/reponame
#
# new structure becomes:
# project
#   ├── .bare
#   ├── feature
#   └── main
alias gclb='f(){ git clone --bare "$@" .bare }; f'
alias repo='f(){
  mkdir -p "$HOME/Repos/$1";
  cd "$HOME/Repos/$1";
  gclb "[email protected]:$1.git";
  echo "gitdir: ./.bare" > .git;
  git worktree add main;
}; f'

if this feature gets added, I guess it also makes sense to not default to opening multiple windows (one for each worktree) upon switching? (this is the same behaviour as tms refresh). This behaviour could all be baked into tms switch --only-worktrees as described above. Would also maybe be nice to have it opt-out for the normal switching too? eg. tms switch --single-window 🤔.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants