The dotfiles manager.
feat: dotman list
1 file changed, +26 -0
+26-0src/main.rs
| @@ -26,6 +26,8 @@ enum Commands { | ||
| 26 | 26 | Update, |
| 27 | 27 | /// List active links in ~/.config that point into dotman |
| 28 | 28 | Active, |
| 29 | + /// List repositories installed in the dotman store | |
| 30 | + List, | |
| 29 | 31 | /// Generate shell completions to stdout (bash|zsh|fish|powershell|elvish) |
| 30 | 32 | Completions { shell: Shell }, |
| 31 | 33 | } |
| @@ -61,6 +63,7 @@ fn main() -> Result<()> { | ||
| 61 | 63 | Commands::Link(args) => cmd_link(&args.name, &args.target), |
| 62 | 64 | Commands::Update => cmd_update(), |
| 63 | 65 | Commands::Active => cmd_active(), |
| 66 | + Commands::List => cmd_list(), | |
| 64 | 67 | Commands::Completions { shell } => cmd_completions(shell), |
| 65 | 68 | } |
| 66 | 69 | } |
| @@ -304,3 +307,26 @@ fn cmd_active() -> Result<()> { | ||
| 304 | 307 | } |
| 305 | 308 | Ok(()) |
| 306 | 309 | } |
| 310 | + | |
| 311 | +fn cmd_list() -> Result<()> { | |
| 312 | + ensure_dotman_dir()?; | |
| 313 | + let root = Path::new(DOTMAN_DIR); | |
| 314 | + let mut repos: Vec<String> = Vec::new(); | |
| 315 | + for entry in fs::read_dir(root).with_context(|| format!("Reading {}", DOTMAN_DIR))? { | |
| 316 | + let entry = entry?; | |
| 317 | + let path = entry.path(); | |
| 318 | + if !path.is_dir() { continue; } | |
| 319 | + let name = match path.file_name().and_then(|s| s.to_str()) { | |
| 320 | + Some(s) => s.to_string(), | |
| 321 | + None => continue, | |
| 322 | + }; | |
| 323 | + repos.push(name); | |
| 324 | + } | |
| 325 | + repos.sort(); | |
| 326 | + if repos.is_empty() { | |
| 327 | + println!("No repositories installed in {}.", DOTMAN_DIR); | |
| 328 | + } else { | |
| 329 | + for r in repos { println!("{}", r); } | |
| 330 | + } | |
| 331 | + Ok(()) | |
| 332 | +} |