()
| 549 | } |
| 550 | |
| 551 | func FixupWaveZshHistory() error { |
| 552 | if runtime.GOOS != "darwin" { |
| 553 | return nil |
| 554 | } |
| 555 | |
| 556 | hasHistory, size := HasWaveZshHistory() |
| 557 | if !hasHistory { |
| 558 | return nil |
| 559 | } |
| 560 | |
| 561 | zshDir := GetLocalZshZDotDir() |
| 562 | waveHistFile := filepath.Join(zshDir, ZshHistoryFileName) |
| 563 | |
| 564 | if size == 0 { |
| 565 | err := os.Remove(waveHistFile) |
| 566 | if err != nil { |
| 567 | log.Printf("error removing wave zsh history file %s: %v\n", waveHistFile, err) |
| 568 | } |
| 569 | return nil |
| 570 | } |
| 571 | |
| 572 | log.Printf("merging wave zsh history %s into ~/.zsh_history\n", waveHistFile) |
| 573 | |
| 574 | homeDir, err := os.UserHomeDir() |
| 575 | if err != nil { |
| 576 | return fmt.Errorf("error getting home directory: %w", err) |
| 577 | } |
| 578 | realHistFile := filepath.Join(homeDir, ".zsh_history") |
| 579 | |
| 580 | isExtended, err := IsExtendedZshHistoryFile(realHistFile) |
| 581 | if err != nil { |
| 582 | return fmt.Errorf("error checking if history is extended: %w", err) |
| 583 | } |
| 584 | |
| 585 | hasExtendedStr := "false" |
| 586 | if isExtended { |
| 587 | hasExtendedStr = "true" |
| 588 | } |
| 589 | |
| 590 | quotedWaveHistFile := utilfn.ShellQuote(waveHistFile, true, -1) |
| 591 | |
| 592 | script := fmt.Sprintf(` |
| 593 | HISTFILE=~/.zsh_history |
| 594 | HISTSIZE=999999 |
| 595 | SAVEHIST=999999 |
| 596 | has_extended_history=%s |
| 597 | [[ $has_extended_history == true ]] && setopt EXTENDED_HISTORY |
| 598 | fc -RI |
| 599 | fc -RI %s |
| 600 | fc -W |
| 601 | `, hasExtendedStr, quotedWaveHistFile) |
| 602 | |
| 603 | ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second) |
| 604 | defer cancelFn() |
| 605 | |
| 606 | cmd := exec.CommandContext(ctx, "zsh", "-f", "-i", "-c", script) |
| 607 | cmd.Stdin = nil |
| 608 | envStr := envutil.SliceToEnv(os.Environ()) |
no test coverage detected