Compute the `~/.cursor/projects` directory slug Cursor derives from a workspace path: every normal path component joined with `-`, case preserved (verified against real `~/.cursor/projects` entries). Returns `None` for non-UTF-8, relative, or traversal-containing paths.
(project_root: &Path)
| 548 | /// preserved (verified against real `~/.cursor/projects` entries). |
| 549 | /// Returns `None` for non-UTF-8, relative, or traversal-containing paths. |
| 550 | pub fn cursor_project_slug(project_root: &Path) -> Option<String> { |
| 551 | let mut parts = Vec::new(); |
| 552 | for component in project_root.components() { |
| 553 | match component { |
| 554 | std::path::Component::Normal(part) => parts.push(part.to_str()?), |
| 555 | std::path::Component::RootDir | std::path::Component::Prefix(_) => {} |
| 556 | std::path::Component::CurDir | std::path::Component::ParentDir => return None, |
| 557 | } |
| 558 | } |
| 559 | (!parts.is_empty()).then(|| parts.join("-")) |
| 560 | } |
| 561 | |
| 562 | /// Enumerate every *existing* directory that [`cursor_project_slug`] would |
| 563 | /// encode to `slug`, by walking the filesystem from `project_root`'s root and |