joshmedeski / sesh

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

doesn't connect to first session #76

Closed znd4 closed 4 months ago

znd4 commented 4 months ago

What happened?

when I run sesh connect nixfiles, I end up with a new session in /home/$USER with name $USER instead of connecting to my existing session named nixfiles (which shows up in sesh list -t

sesh connect works as expected with every other session (including sesh connect $USER).

I think the important detail here is that nixfiles is the first session -- my default wezterm program is (almost)

tmux new -Asnixfiles

EDIT: Extra debugging: I killed the existing nixfiles and $USER sessions, ran sesh connect ~/path/to/nixfiles at which point sesh connect worked for all sessions.

I suppose it might be possible as a workaround to write a tmux entry script that always kills the first session, but it seems like a bit of a headache

Version

dev (I'm building from source, currently locked to be2badd29206f66803b76b62b23f6f5e05befe08)

Relevant log output

No response

Reviewed

joshmedeski commented 4 months ago

Okay, so I know what is happening.

The intention of sesh is for every session name to be identical to the directory it's pointed to. So the logic currently looks up if a tmux session exists by the path of the tmux session, not the session name.

In your case, the nixfiles session is pointing to the $HOME directory and generating a new session based off your user name, not the custom name you defined.

The reason I did this was to make it easier to identify a tmux session from a zoxide result, rather than having to convert a zoxide result into a session name before doing the comparison.

I do recommend you avoid custom tmux sessions names when using sesh and always allow sesh to be the one to name tmux sessions on your behalf.

Would you like sesh to behave differently? I'm open to changing it if it works well for the sesh community.

bchubb-web commented 4 months ago

I have encountered this aswell, my idea would be to rename the 0 session on the first opening of sesh, to its folder name

joshmedeski commented 4 months ago

Sesh doesn't do any sort of transformation of sessions once they exist, it only creates or attaches/switches sessions. I recommend whatever logic you have create the first session always be a valid sesh session.

znd4 commented 4 months ago

Hmm, I thought that only tmux panes / windows had working directories -- didn't know that sessions did as well.

I don't think it's worth changing sesh's behavior in this instance -- hopefully this issue is enough documentation for people.

FWIW, I've changed my startup script to a simplified version of the one from the readme:

sesh connect $(sesh list | fzf)
joshmedeski commented 4 months ago

My start script does something very similar, glad to clarify things.

And yes, sessions have a session_path assigned on creation:

image