Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

add OLLAMA_NOHISTORY to turn off history in interactive mode (#4508)

Patrick Devine105186aa179c
diff --git a/cmd/cmd.go b/cmd/cmd.go
index dff8d7c10..3b60334c5 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -1078,12 +1078,24 @@ func versionHandler(cmd *cobra.Command, _ []string) {
}
}
-func appendHostEnvDocs(cmd *cobra.Command) {
- const hostEnvDocs = `
+type EnvironmentVar struct {
+ Name string
+ Description string
+}
+
+func appendEnvDocs(cmd *cobra.Command, envs []EnvironmentVar) {
+ if len(envs) == 0 {
+ return
+ }
+
+ envUsage := `
Environment Variables:
- OLLAMA_HOST The host:port or base URL of the Ollama server (e.g. http://localhost:11434)
`
- cmd.SetUsageTemplate(cmd.UsageTemplate() + hostEnvDocs)
+ for _, e := range envs {
+ envUsage += fmt.Sprintf(" %-16s %s\n", e.Name, e.Description)
+ }
+
+ cmd.SetUsageTemplate(cmd.UsageTemplate() + envUsage)
}
func NewCLI() *cobra.Command {
@@ -1220,6 +1232,10 @@ Environment Variables:
RunE: DeleteHandler,
}
+ ollamaHostEnv := EnvironmentVar{"OLLAMA_HOST", "The host:port or base URL of the Ollama server (e.g. http://localhost:11434)"}
+ ollamaNoHistoryEnv := EnvironmentVar{"OLLAMA_NOHISTORY", "Disable readline history"}
+ envs := []EnvironmentVar{ollamaHostEnv}
+
for _, cmd := range []*cobra.Command{
createCmd,
showCmd,
@@ -1231,7 +1247,12 @@ Environment Variables:
copyCmd,
deleteCmd,
} {
- appendHostEnvDocs(cmd)
+ switch cmd {
+ case runCmd:
+ appendEnvDocs(cmd, []EnvironmentVar{ollamaHostEnv, ollamaNoHistoryEnv})
+ default:
+ appendEnvDocs(cmd, envs)
+ }
}
rootCmd.AddCommand(
diff --git a/cmd/interactive.go b/cmd/interactive.go
index 1078590c0..f9157bd83 100644
--- a/cmd/interactive.go
+++ b/cmd/interactive.go
@@ -182,6 +182,10 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
return err
}
+ if os.Getenv("OLLAMA_NOHISTORY") != "" {
+ scanner.HistoryDisable()
+ }
+
fmt.Print(readline.StartBracketedPaste)
defer fmt.Printf(readline.EndBracketedPaste)