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

Adds create option to attach #587

Closed
wants to merge 1 commit into from

Conversation

pedrohjordao
Copy link

  • Adds create option to attach that will create a new session if one doesn't already exists with the given name
  • Small refactor to remove code duplication

Closes #541

- Adds create option to attach that will create a new session if one doesn't already exists with the given name
- Small refactor to remove code duplication
Copy link
Member

@kunalmohan kunalmohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pedrohjordao! Thank you for taking this up 🙂! It is a much-needed feature.
This PR is going in the right direction, but there are a couple of cases that need to be handled differently. I've mentioned them below. Let me know if more clarifications are needed.

let client_info = match opts.command.clone() {
Some(Command::Sessions(Sessions::Attach {mut session_name, force, create})) => {
let is_new_session = match (session_name.as_ref(), create) {
(Some(_), true) => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it looks like it will always create a new session. We need to check if a session exists or not. In case it exists attach to it, otherwise create a new one.
You will probably have to change the assert_session() function (and maybe rename it) to return a bool corresponding to whether a session exists or not. And we can possibly remove the assert_session_ne() method in favour of this one.

Comment on lines +69 to +71
(None, _) => {
session_name = Some(get_active_session());
false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we need to consider the --create flag as well-

  1. Flag is not present- If a single session exists attach to it, otherwise exit with a message.
  2. Flag is present- Is a single session exists, attach to it. If no session exists, create a new one with a random name (generated using names::Generator). If >1 sessions exist, exit with a message.

@pedrohjordao
Copy link
Author

Thanks, I'll take your comments and update the pr soon

@pedrohjordao
Copy link
Author

Just a heads up: I still plan on working on this, but I'm in the middle of a change of jobs and country, so it might take a couple of weeks until a can pick this up again. If anyone wants to work on it, feel free.

@a-kenji
Copy link
Contributor

a-kenji commented Sep 19, 2021

Thank you for the work on this feature!
It has now been implemented by #731.

@a-kenji a-kenji closed this Sep 19, 2021
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

Successfully merging this pull request may close these issues.

Feature request: zellij attach --create
3 participants