From ab7db995aa8bf93d22e0303b9c3c3c02166f0ad3 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 16 Oct 2022 09:51:52 -0700 Subject: [PATCH] Restore stdin import for the hishtory import command --- client/lib/lib.go | 14 ++++++++------ hishtory.go | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/client/lib/lib.go b/client/lib/lib.go index dfc43d1..01c76a6 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -391,7 +391,7 @@ func CheckFatalError(err error) { } } -func ImportHistory(ctx *context.Context) (int, error) { +func ImportHistory(ctx *context.Context, shouldReadStdin bool) (int, error) { config := hctx.GetConf(ctx) if config.HaveCompletedInitialImport { // Don't run an import if we already have run one. This avoids importing the same entry multiple times. @@ -407,11 +407,13 @@ func ImportHistory(ctx *context.Context) (int, error) { return 0, fmt.Errorf("failed to parse zsh history: %v", err) } historyEntries = append(historyEntries, extraEntries...) - // extraEntries, err = readStdin() - // if err != nil { - // return 0, fmt.Errorf("failed to read stdin: %v", err) - // } - // historyEntries = append(historyEntries, extraEntries...) + if shouldReadStdin { + extraEntries, err = readStdin() + if err != nil { + return 0, fmt.Errorf("failed to read stdin: %v", err) + } + historyEntries = append(historyEntries, extraEntries...) + } db := hctx.GetDb(ctx) currentUser, err := user.Current() if err != nil { diff --git a/hishtory.go b/hishtory.go index c542d84..b785015 100644 --- a/hishtory.go +++ b/hishtory.go @@ -75,7 +75,7 @@ func main() { if os.Getenv("HISHTORY_TEST") == "" { fmt.Println("Importing existing shell history...") ctx := hctx.MakeContext() - numImported, err := lib.ImportHistory(ctx) + 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) @@ -83,7 +83,7 @@ func main() { } case "import": ctx := hctx.MakeContext() - numImported, err := lib.ImportHistory(ctx) + numImported, err := lib.ImportHistory(ctx, true) lib.CheckFatalError(err) if numImported > 0 { fmt.Printf("Imported %v history entries from your existing shell history\n", numImported)