A file-based task manager
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fzf-pick the namespace when tsk switch is run with no name

`tsk switch` (and `tsk namespace switch`) now accept the name as
optional. When omitted, fzf-pick from existing namespaces with a
`<new>` sentinel for entering a fresh name at a prompt.

`tsk namespace create <name>` is unchanged (always requires a name).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

+37 -8
+37 -8
src/main.rs
··· 290 290 }, 291 291 292 292 /// Switch to a different namespace. Shorthand for `tsk namespace switch`. 293 - Switch { name: String }, 293 + /// With no name, fzf-picks from existing namespaces (plus a `<new>` 294 + /// sentinel for creating one on the fly). 295 + Switch { name: Option<String> }, 294 296 295 297 /// Reopens an archived task, recreating the symlink and adding it back to the stack. 296 298 Reopen { ··· 340 342 List, 341 343 /// Print the current namespace name. 342 344 Current, 343 - /// Switch to (create on first push of) the given namespace. 344 - Switch { name: String }, 345 + /// Switch to (create on first push of) the given namespace. With no 346 + /// name, fzf-picks from existing namespaces. 347 + Switch { name: Option<String> }, 345 348 /// Create an empty namespace and switch to it. 346 349 Create { name: String }, 347 350 /// Delete every ref under the given namespace. Refuses if the namespace is ··· 492 495 Commands::Log { tsk_id } => command_log(dir, tsk_id), 493 496 Commands::Prop { action } => command_prop(dir, action), 494 497 Commands::Namespace { action } => command_namespace(dir, action), 495 - Commands::Switch { name } => command_namespace_switch(dir, &name), 498 + Commands::Switch { name } => command_namespace_switch(dir, name), 496 499 } 497 500 } 498 501 ··· 1106 1109 Ok(()) 1107 1110 } 1108 1111 1109 - fn command_namespace_switch(dir: PathBuf, name: &str) -> Result<()> { 1112 + fn command_namespace_switch(dir: PathBuf, name: Option<String>) -> Result<()> { 1110 1113 let ws = Workspace::from_path(dir)?; 1111 - ws.switch_namespace(name)?; 1112 - eprintln!("Switched to namespace '{name}'"); 1114 + let target = match name { 1115 + Some(n) => n, 1116 + None => pick_namespace(&ws)?, 1117 + }; 1118 + ws.switch_namespace(&target)?; 1119 + eprintln!("Switched to namespace '{target}'"); 1113 1120 Ok(()) 1114 1121 } 1115 1122 1123 + /// fzf-pick a namespace from the workspace's existing list, with a `<new>` 1124 + /// sentinel for entering one that doesn't exist yet. 1125 + fn pick_namespace(ws: &Workspace) -> Result<String> { 1126 + let mut candidates = ws.list_namespaces()?; 1127 + candidates.push(NEW_SENTINEL.to_string()); 1128 + let picked = fzf::select::<_, String, _>(candidates, ["--prompt=namespace> "])? 1129 + .ok_or_else(|| errors::Error::Parse("No namespace selected".into()))?; 1130 + if picked == NEW_SENTINEL { 1131 + prompt_line("new namespace name: ") 1132 + } else { 1133 + Ok(picked) 1134 + } 1135 + } 1136 + 1116 1137 fn command_namespace(dir: PathBuf, action: NamespaceAction) -> Result<()> { 1117 1138 let ws = Workspace::from_path(dir)?; 1118 1139 match action { ··· 1126 1147 println!("{marker}{ns}"); 1127 1148 } 1128 1149 } 1129 - NamespaceAction::Switch { name } | NamespaceAction::Create { name } => { 1150 + NamespaceAction::Switch { name } => { 1151 + let target = match name { 1152 + Some(n) => n, 1153 + None => pick_namespace(&ws)?, 1154 + }; 1155 + ws.switch_namespace(&target)?; 1156 + eprintln!("Switched to namespace '{target}'"); 1157 + } 1158 + NamespaceAction::Create { name } => { 1130 1159 ws.switch_namespace(&name)?; 1131 1160 eprintln!("Switched to namespace '{name}'"); 1132 1161 }