Преглед изворни кода

Merge branch 'feat-rm-empty-lines' into devel

Edvinas Valatka пре 10 година
родитељ
комит
055eec1a23
1 измењених фајлова са 8 додато и 5 уклоњено
  1. 8 5
      main.go

+ 8 - 5
main.go

@@ -13,8 +13,13 @@ func main() {
 	scanner := bufio.NewScanner(histfile)
 	var i = 0
 	for scanner.Scan() {
-		history[strings.TrimSpace(scanner.Text())] = i
-		i++
+		line := strings.TrimSpace(scanner.Text())
+		if len(line) > 0 {
+			if history[line] == 0 {
+				history[line] = i
+				i++
+			}
+		}
 	}
 
 	defer histfile.Close()
@@ -27,9 +32,7 @@ func main() {
 	newhistfile, _ := os.OpenFile(mktmpfile(), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
 	newhistfile.Truncate(0)
 	for _, key := range ah {
-		if len(strings.TrimSpace(key)) > 0 {
-			newhistfile.WriteString(key + "\n")
-		}
+		newhistfile.WriteString(key + "\n")
 	}
 	newhistfile.Sync()
 	CopyFile(mktmpfile(), gethistfile())