From 738939e4c95a8b65a74923f45264f1d82723807a Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 7 Mar 2022 18:56:22 -0400 Subject: [PATCH] fix: remove duplicate binary suggestions (fixes #105) --- complete.go | 2 ++ main.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/complete.go b/complete.go index 56009fb..301b051 100644 --- a/complete.go +++ b/complete.go @@ -69,6 +69,8 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) { } } + completions = removeDupes(completions) + return completions, query } diff --git a/main.go b/main.go index af7f0b8..b20cdb7 100644 --- a/main.go +++ b/main.go @@ -268,3 +268,16 @@ func expandHome(path string) string { return strings.Replace(defaultHistDir, "~", homedir, 1) } + +func removeDupes(slice []string) []string { + all := make(map[string]bool) + newSlice := []string{} + for _, item := range slice { + if _, val := all[item]; !val { + all[item] = true + newSlice = append(newSlice, item) + } + } + + return newSlice +}