| 123456789101112131415161718192021222324252627 |
- package main
- import (
- "bufio"
- "os"
- "strings"
- )
- var history = make(map[string]int)
- func main() {
- histfile, _ := os.Open(gethistfile())
- scanner := bufio.NewScanner(histfile)
- for scanner.Scan() {
- line := scanner.Text()
- history[strings.TrimSpace(line)] = 0
- }
- defer histfile.Close()
- newhistfile, _ := os.OpenFile(mktmpfile(), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
- newhistfile.Truncate(0)
- for key, _ := range history {
- newhistfile.WriteString(key + "\n")
- }
- newhistfile.Sync()
- CopyFile(mktmpfile(), gethistfile())
- defer newhistfile.Close()
- }
|