From 07bf84a4f95205f5a741b3883ec4716ac280a54d Mon Sep 17 00:00:00 2001 From: David Dworken Date: Thu, 20 Oct 2022 23:42:08 -0700 Subject: [PATCH] Skip importing the existing shell history if install is ran and hishtory already has a significant number of history entries --- hishtory.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hishtory.go b/hishtory.go index 8bd57fc..753c9c3 100644 --- a/hishtory.go +++ b/hishtory.go @@ -73,13 +73,18 @@ func main() { case "install": lib.CheckFatalError(lib.Install()) if os.Getenv("HISHTORY_TEST") == "" { - fmt.Println("Importing existing shell history...") - ctx := hctx.MakeContext() - // TODO: skip doing this if this is an update - numImported, err := lib.ImportHistory(ctx, false) + db, err := hctx.OpenLocalSqliteDb() lib.CheckFatalError(err) - if numImported > 0 { - fmt.Printf("Imported %v history entries from your existing shell history\n", numImported) + data, err := data.Search(db, "", 10) + lib.CheckFatalError(err) + if len(data) < 10 { + fmt.Println("Importing existing shell history...") + ctx := hctx.MakeContext() + numImported, err := lib.ImportHistory(ctx, false) + lib.CheckFatalError(err) + if numImported > 0 { + fmt.Printf("Imported %v history entries from your existing shell history\n", numImported) + } } } case "import":