Skip to content

Commit fb4306d

Browse files
shendiaomowangkuiyi
authored andcommitted
Fix duplicated history (#1719)
1 parent c65ac81 commit fb4306d

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cmd/repl/prompt.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type promptState struct {
7070
livePrefix string
7171
enableLivePrefix bool
7272
statement string
73+
lastStatement string
7374
keywords []string
7475
history []string
7576
historyFileName string
@@ -90,6 +91,7 @@ func (p *promptState) execute(in string, cb func(string)) {
9091
p.enableLivePrefix = false
9192
fmt.Println()
9293
cb(p.statement)
94+
p.lastStatement = p.statement
9395
p.statement = ""
9496
return
9597
}
@@ -137,7 +139,7 @@ func (p *promptState) initHistory() {
137139
}
138140

139141
func (p *promptState) updateHistory() {
140-
if p.statement != "" {
142+
if p.statement != "" && p.statement != p.lastStatement {
141143
f, err := os.OpenFile(p.historyFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
142144
if err != nil {
143145
return

0 commit comments

Comments
 (0)