diff --git a/src/command.rs b/src/command.rs index 4dcad7f..166c67f 100644 --- a/src/command.rs +++ b/src/command.rs @@ -127,10 +127,18 @@ pub fn new(pargs: &mut Arguments) { // get target and error out if not provided let args = pargs.clone().finish(); - if args.len() < 1 { error::missing_target(); } - // get target session and optional command - let title = args.get(0).unwrap().to_string_lossy(); + // collect name and command arguments + let title: String; + if args.len() < 1 { + // missing name will attempt to fall back to repository + let repo = util::repo_root(current_dir().unwrap()); + if repo.is_none() { error::missing_target(); } + + title = repo.unwrap().file_name().unwrap().to_string_lossy().to_string(); + } else { + title = args.get(0).unwrap().to_string_lossy().to_string(); + } let command = args.get(1); // build command diff --git a/src/util.rs b/src/util.rs index bf1e17b..0d0bae8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -38,13 +38,13 @@ pub fn session_exists(target: String) -> bool { } /// recursively attempt to find a git root directory -fn repo_root(path: PathBuf) -> Option { +pub fn repo_root(path: PathBuf) -> Option { // if .git dir is found, return if path.join(".git").exists() { return Some(path); } // otherwise, attempt to traverse let parent = path.parent(); - if let Some(parent) = parent { git_traverse(parent.to_path_buf()) } + if let Some(parent) = parent { repo_root(parent.to_path_buf()) } else { None } }