MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / FixupWaveZshHistory

Function FixupWaveZshHistory

pkg/util/shellutil/shellutil.go:551–623  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

549}
550
551func 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())

Callers 1

mainFunction · 0.92

Calls 8

ShellQuoteFunction · 0.92
SliceToEnvFunction · 0.92
RmEnvFunction · 0.92
EnvToSliceFunction · 0.92
HasWaveZshHistoryFunction · 0.85
GetLocalZshZDotDirFunction · 0.85
IsExtendedZshHistoryFileFunction · 0.85
CombinedOutputMethod · 0.80

Tested by

no test coverage detected