main.go 627 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "bufio"
  4. "os"
  5. "strings"
  6. )
  7. var history = make(map[string]int)
  8. func main() {
  9. histfile, _ := os.Open(gethistfile())
  10. scanner := bufio.NewScanner(histfile)
  11. for scanner.Scan() {
  12. line := scanner.Text()
  13. history[strings.TrimSpace(line)] = 0
  14. }
  15. defer histfile.Close()
  16. newhistfile, _ := os.OpenFile(mktmpfile(), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
  17. newhistfile.Truncate(0)
  18. for key, _ := range history {
  19. newhistfile.WriteString(key + "\n")
  20. }
  21. newhistfile.Sync()
  22. CopyFile(mktmpfile(), gethistfile())
  23. defer newhistfile.Close()
  24. }