joshmedeski / sesh

Smart session manager for the terminal
MIT License
410 stars 16 forks source link

Add tmuxp support #87

Open kohane27 opened 3 months ago

kohane27 commented 3 months ago

What would you like sesh to do?

Hello there! Thank you for creating sesh and the previous t-smart-tmux-session-manager!

I'm trying to migrate from t to sesh but facing the following problem.

Description

I'm using tmuxp to fzf find and load tmux sessions:

tmuxp load -d $(ls ~/.config/tmuxp | fzf)

The following is extracted from my modified t:

# check if selection is in is TMUXP
WORKSPACE_NAME=$($TMUXP_LS | grep "$RESULT")
if [ ! -z "$WORKSPACE_NAME" -a "$WORKSPACE_NAME" != " " ]; then
    $TMUXP_PATH load -d "$WORKSPACE_NAME" >/dev/null 2>&1
    tmux switch-client -t "$WORKSPACE_NAME"
    exit 0
fi

I'm hoping sesh would have the following:

  1. custom directories, i.e., sesh list ~/.config/tmuxp
  2. custom command, i.e., tmuxp load -d

Such that I can use the following:

sesh $CUSTOM_COMMAND "$(sesh list $CUSTOM_DIR | fzf-tmux -p 55%,60%)"

I understand that this may be out of project scope. I hacked on the original t because it's a bash script, but I'm not sure about golang.

Thank you again!

joshmedeski commented 3 months ago

Hi @kohane27 thanks for the suggestion. I think integrating with tmuxp is possible.

Would you want non-tmuxp commands to still work (ex: listing existing sessions and attaching to current tmux sessions). If so, we'll probably need to adjust your suggestions to better work alongside existing functionality (rather than replacing it).

I've got some ideas but please clarify how you'd expect this to work alongside the current features sesh has to offer.

kohane27 commented 3 months ago

Thank you for considering this feature request! Initially, I thought it'd be out of project scope but then I saw the feature "clone a git repo and connect to it as a session" so I thought loading a tmux session would be appropriate enough.

Would you want to list tmux sessions, zoxide results, and tmuxp configs at the same time?

I think this would be best to leave it to the user to implement? What I current use indeed combine zoxide results and tmuxp configs:

2024-03-26-18-28-

Would you want to conditionally load tmuxp configs if the session already exists or there is not config file that matches the result?

Would you want non-tmuxp commands to still work (ex: listing existing sessions and attaching to current tmux sessions).

Thank you for considering these use cases! The following is what I have in mind:

COMMANDS:
   list, l      List sessions
   connect, cn  Connect to the given session
   load, load   Load a given session

Usage:

sesh load "$(sesh list -s | fzf-tmux -p 55%,60%)"

Note: -s for session

Given there are bind flags like --bind 'ctrl-a:change-prompt(⚡ )+reload(sesh list)', it'd be easy enough to switch to other sesh lists, i.e., switching between sesh list -s or -t or -z on the fly is convenient enough.

Things to consider

There are many session managers like tmuxp, most notably tmuxinator:

tmuxinator start [project] -n [name] -p [project-config]

If sesh supports tmuxinator then it'd benefit more people. Maybe something similar to the following config?

[[session_path]]
# tmuxp
SESSION_DIR = "~/.config/tmuxp"
SESSION_MANAGER_COMMAND = "tmuxp load -d fzf-result-tmuxp-config-name"

# tmuxinator
SESSION_DIR = "~/.config/tmuxinator"
SESSION_MANAGER_COMMAND = "tmuxinator start --project-config=path/to/fzf/result/project.yaml"

Thank you again!

joshmedeski commented 3 months ago

I'd prefer to keep the connect command as-is, and extend it's functionality.

I think this approach could work:

[[session]]
name = "dotfiles"
path = "~/c/dotfiles"
tmuxp_config = "~/.config/tmuxp/dotfiles.yaml"

We could update the session config over time to offer different options, like tmuxinator as well.

[[session]]
name = "dotfiles"
path = "~/c/dotfiles"
tmuxinator_config = "~/.config/tmuxinator/dotfiles.yaml"

Do you like this approach? Then, sesh connect would be the same, and when you chose a path that matches a config, it would detect the config and run it.

kohane27 commented 3 months ago

Hello @joshmedeski

Apologies for my late reply.

Thank you for the suggestion:) I think this approach of yours is cleaner!

I'm looking forward to testing when you have time to implement this feature. Thank you again!