'new' now attempts to fall back to repository root name
This commit is contained in:
parent
3dc0e82ad6
commit
90f3b9a999
2 changed files with 13 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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<PathBuf> {
|
||||
pub fn repo_root(path: PathBuf) -> Option<PathBuf> {
|
||||
// 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 }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue