From 8dd3f692b83822c37f9e3b6940bd78ae6a900d13 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 29 Dec 2018 20:20:45 +0300 Subject: [PATCH] remove duplicates in autocompletion --- complete.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/complete.go b/complete.go index 29da1fe6..6fe78fc7 100644 --- a/complete.go +++ b/complete.go @@ -275,6 +275,15 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) { words = append(words, c) } sort.Strings(words) + j := 0 + for i := 1; i < len(words); i++ { + if words[j] == words[i] { + continue + } + j++ + words[i], words[j] = words[j], words[i] + } + words = words[:j+1] matches, longest = matchWord(s, words) longestAcc = []rune(longest) case 2: