-
Notifications
You must be signed in to change notification settings - Fork 155
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
feat: tmux session attach mode #901
Conversation
Hi, sorry for the late reply! Would you mind telling me the difference between |
Thanks for the reply! Basically, here's how it works Here's a video that, hopefully, demonstrates that. out.mp4 |
I get it, thanks for the explanation and the demo video:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General impl looks good, left some comments:)
config.example.toml
Outdated
# the newly crated tmux session, creating the session | ||
# and only attaching to it if not inside tmux | ||
# (default: create, allowed values: "create", "create_and_switch_client") | ||
# tmux_session_attach_mode = "create" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking about the naming, what about we call them:
- AttachIfNotInASession
- AlwasyAttach
I think switch_client
is too technical, thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed some names, also dropping attach
infix from tmux params, to not repeat it
src/config.rs
Outdated
/// The preferred way to run the new tmux session | ||
#[arg(long = "tmux-session-attach-mode")] | ||
tmux_session_attach_mode: Option<TmuxSessionAttachMode>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to add this CLI option, I think this feature is more like a static feature, one won't need to frequently change it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
src/config.rs
Outdated
@@ -967,6 +986,19 @@ impl Config { | |||
.unwrap_or(false) | |||
} | |||
|
|||
/// The preferred way to run the new tmux session. | |||
pub fn tmux_session_attach_mode(&self) -> TmuxSessionAttachMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this function private as well if we want developers to use .tmux_config()
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/steps/tmux.rs
Outdated
// Only attach to the newly-created session if we're not currently in a tmux session. | ||
TmuxSessionAttachMode::Create if is_inside_tmux => { | ||
println!("Topgrade launched in a new tmux session"); | ||
return Ok(()); | ||
} | ||
TmuxSessionAttachMode::CreateAndSwitchClient if is_inside_tmux => { | ||
tmux.build().args(["switch-client", "-t", &session]).exec() | ||
} | ||
TmuxSessionAttachMode::Create | TmuxSessionAttachMode::CreateAndSwitchClient => { | ||
tmux.build().args(["attach-session", "-t", &session]).exec() | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about writing it in this way, would it be a little bit clearer?
TmuxSessionAttachModule::Create => {
if is_inside_tmux {
println!("Topgrade launched in a new tmux session");
return Ok(());
} else {
tmux.build().args(["attach-session", "-t", &session]).exec()
}
}
TmuxSessionAttachModule::CreateAndSwitchClient => {
if is_inside_tmux {
tmux.build().args(["switch-client", "-t", &session]).exec()
} else {
tmux.build().args(["attach-session", "-t", &session]).exec()
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it if it's easier, just felt bad to repeat attach-session
call twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just felt bad to repeat attach-session call twice
Yeah, that's indeed one drawback. Though I prefer readability, which will make maintenance easier:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for implementing the feature!
What does this PR do
This will allow the user to choose between just creating a session when in tmux, or switching the client to the newly created session. It's useful for my workflow revolving around tmux, where having forced a separate session with no quick way to attach to it created friction
Standards checklist
CONTRIBUTING.md
For new steps
--dry-run
option works with this step--yes
option works with this step if it is supported bythe underlying command
If you developed a feature or a bug fix for someone else and you do not have the
means to test it, please tag this person here.