{"record":{"id":"9499dc7b97e35f9f","repo":"atuinsh/atuin","slug":"no-commands-found-in-history","errorCode":null,"errorMessage":"No commands found in history","messagePattern":"No commands found in history","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin/src/command/client/scripts.rs","lineNumber":248,"sourceCode":"            // Get the last N+1 commands, filtering by the default mode\n            let filters = [settings.default_filter_mode(context.git_root.is_some())];\n\n            let mut history =\n                history_db.list(filters, &context, Some(count), false, false, None).await?;\n\n            // Reverse to get chronological order\n            history.reverse();\n\n            // Skip the most recent command (which would be the atuin scripts new command itself)\n            if !history.is_empty() {\n                history.pop(); // Remove the most recent command\n            }\n\n            // Format the commands into a script\n            let commands: Vec<String> = history.iter().map(|h| h.command.clone()).collect();\n\n            if commands.is_empty() {\n                bail!(\"No commands found in history\");\n            }\n\n            let script_text = commands.join(\"\\n\");\n\n            // Only open editor if --no-edit is not specified\n            if new_script.no_edit {\n                Some(script_text)\n            } else {\n                // Open the editor with the commands pre-loaded\n                Some(Self::open_editor(Some(&script_text))?)\n            }\n        } else if let Some(script_path) = new_script.script {\n            let script_content = std::fs::read_to_string(script_path)?;\n            Some(script_content)\n        } else if !stdin.is_terminal() {\n            let mut buffer = String::new();\n            stdin.read_to_string(&mut buffer)?;\n            Some(buffer)","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin/src/command/client/scripts.rs#L230-L266","documentation":"When creating a script from history (`atuin scripts new`), atuin collects the selected history entries' commands and refuses to build an empty script. If the filtered history list contains no commands, it bails with \"No commands found in history\" instead of opening the editor with an empty file.","triggerScenarios":"Running `atuin scripts new` with filters/query that match zero history entries, so `commands.is_empty()` is true after collecting from the history iterator.","commonSituations":"Typing a search query that matches nothing, an empty local history database (fresh install, history not yet imported), or too-narrow time/directory/host filters.","solutions":["Broaden or correct the search query/filter so it matches history entries.","Run `atuin import auto` (or your shell's import) to populate history, then retry.","Check that history exists: run `atuin history list` and confirm the commands you expect are present.","Verify the correct `--cwd`/`--host`/time-range filters are being passed."],"exampleFix":"// before\natuin scripts new \"npm tes\"   # typo matches nothing\n// after\natuin scripts new \"npm test\"  # or run `atuin history list` to find the right text","handlingStrategy":"validation","validationCode":"# shell\nif [ -z \"$(atuin history list 2>/dev/null | head -n1)\" ]; then\n  echo \"history empty; run 'atuin import auto' first\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":"if ! out=$(atuin scripts new \"$query\" 2>&1); then\n  case \"$out\" in\n    *\"No commands found in history\"*) atuin import auto && atuin scripts new \"$query\" ;;\n  esac\nfi","preventionTips":["Verify your query matches history via `atuin history list` before piping into scripts new.","Import history on fresh machines (`atuin import auto`).","Avoid over-narrow cwd/host/time filters when selecting commands."],"tags":["cli","empty-input","history"],"backgroundTag":"empty-result-set","analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}