nikivdev/code · error

No templates found in ~/new/

Error message

No templates found in ~/new/

What it means

Thrown by fuzzy_select_template (src/code.rs:60) when `f new` is run without a template argument and no template directories exist under ~/new/. list_templates() only counts non-hidden subdirectories of ~/new/, so an empty or missing ~/new/ yields zero templates and this bail instead of opening fzf.

Source

Thrown at src/code.rs:60

        let entry = entry?;
        let path = entry.path();
        if path.is_dir() {
            if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
                if !name.starts_with('.') {
                    templates.push(name.to_string());
                }
            }
        }
    }
    templates.sort();
    Ok(templates)
}

/// Fuzzy select a template from ~/new/.
fn fuzzy_select_template() -> Result<Option<String>> {
    let templates = list_templates()?;
    if templates.is_empty() {
        bail!("No templates found in ~/new/");
    }

    let input = templates.join("\n");

    let mut fzf = Command::new("fzf")
        .args(["--height=50%", "--reverse", "--prompt=Template: "])
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .spawn()
        .context("failed to spawn fzf")?;

    fzf.stdin.as_mut().unwrap().write_all(input.as_bytes())?;

    let output = fzf.wait_with_output()?;
    if !output.status.success() {
        return Ok(None);
    }

View on GitHub (pinned to a747e741ae)

Solutions

  1. Create the template root and add at least one template directory: `mkdir -p ~/new/rust-cli`.
  2. Pass a template name explicitly (`f new rust-cli ~/code/myproj`) to bypass fuzzy selection entirely.
  3. Verify ~/new/ resolves to the right place (`echo $HOME; ls ~/new`) and fix $HOME if wrong.
  4. If your templates live elsewhere, move/symlink them into ~/new/.

Example fix

// before
$ f new
Error: No templates found in ~/new/
// after
$ mkdir -p ~/new/rust-cli && cp -r myproject/. ~/new/rust-cli/
$ f new  # fzf picker opens
Defensive patterns

Strategy: validation

Validate before calling

// Shell: ensure the template root has at least one template
[ -d "$HOME/new" ] && [ -n "$(ls -A "$HOME/new" 2>/dev/null)" ] \
  || { echo "~/new/ is empty; add a template dir first"; exit 1; }

Try / catch

match new_from_template(opts) {
    Err(e) if e.to_string().contains("No templates found") => {
        eprintln!("Create ~/new/<template>/ first, or pass a template name explicitly.");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running `f new` (no template arg) via new_from_template -> fuzzy_select_template when ~/new/ does not exist, is empty, or contains only hidden/regular-file entries.

Common situations: Fresh machine where the template root was never set up; HOME misconfigured so ~/new/ resolves to the wrong location; templates stored elsewhere; templates accidentally flattened into files instead of directories.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/3eb3852754cd2aa8. Report an issue: GitHub.