Skip to content

Commit

Permalink
fix(attach): early exit if worktree selection is cancelled (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdenEast authored Oct 23, 2023
1 parent 18a4bbf commit 96b583a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cmd/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@ impl Attach {
fuzzy_match_highlight_style: Style::new().for_stderr().red(),
..Default::default()
};
FuzzySelect::with_theme(&theme)
let selected = FuzzySelect::with_theme(&theme)
.with_prompt("Worktree")
.default(0)
.items(&items)
.interact_opt()
.ok()?
.ok()?;

// The user cancelled the selection, return a different exit code
if selected.is_none() {
std::process::exit(2);
}

selected
}
}
}
Expand All @@ -166,8 +173,9 @@ impl Attach {
})
};

let worktree = get_worktree();
tmux::create_session(&name, selected.to_str().unwrap())?;
if let Some(worktree) = get_worktree() {
if let Some(worktree) = worktree {
tmux::send_command(&name, &format!("cd {}", worktree.path().display()))?;
}
tmux::attach_session(&name)?;
Expand Down

0 comments on commit 96b583a

Please sign in to comment.