Skip to content

Commit

Permalink
add -e option (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnymeller committed May 16, 2024
1 parent bec6add commit bfb96fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use anyhow::Result;

use crate::config::TwmGlobal;
use crate::matches::{find_workspaces_in_dir, SafePath};
use crate::tmux::{get_tmux_sessions, open_workspace, open_workspace_in_group};
use crate::tmux::{
attach_to_tmux_session, get_tmux_sessions, open_workspace, open_workspace_in_group,
};
use clap::Parser;

#[derive(Parser, Default, Debug)]
Expand All @@ -21,6 +23,12 @@ pub struct Arguments {
/// Using this option will override any other layout definitions.
pub layout: bool,

#[clap(short, long)]
/// Prompt user to select an existing tmux session to attach to.
///
/// This nullifies all other options.
pub existing: bool,

#[clap(short, long)]
/// Prompt user to start a new session in the same group as an existing session.
///
Expand Down Expand Up @@ -48,7 +56,18 @@ pub struct Arguments {
pub fn parse() -> Result<()> {
let args = Arguments::parse();

if args.group {
if args.existing {
let existing_sessions = get_tmux_sessions()?;
let session_name = get_skim_selection_from_slice(
&existing_sessions
.iter()
.map(|s| s.as_str())
.collect::<Vec<&str>>(), // TODO: not ideal...
"Select a session to attach to: ",
)?;
attach_to_tmux_session(&session_name)?;
Ok(())
} else if args.group {
let existing_sessions = get_tmux_sessions()?;
let group_session_name = get_skim_selection_from_slice(
&existing_sessions
Expand Down
2 changes: 1 addition & 1 deletion src/tmux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn attach_to_tmux_session_inside_tmux(session_name: &str) -> Result<()> {
Ok(())
}

fn attach_to_tmux_session(session_name: &str) -> Result<()> {
pub fn attach_to_tmux_session(session_name: &str) -> Result<()> {
if std::env::var("TMUX").is_ok() {
attach_to_tmux_session_inside_tmux(session_name)
} else {
Expand Down

0 comments on commit bfb96fc

Please sign in to comment.