Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 949dafb

Browse files
committed
Remove duplicate paths
1 parent 8e02ca2 commit 949dafb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func loadCommandsInto(root *cobra.Command) error {
6565
paths := filepath.SplitList(sdPath)
6666
logrus.Debug("SD_PATH is set to:", sdPath, ", parsed as: ", paths)
6767

68-
for _, path := range append([]string{home, current}, paths...) {
68+
for _, path := range deduplicate(append([]string{home, current}, paths...)) {
6969
cmds, err := visitDir(path)
7070
if err != nil {
7171
return err
@@ -256,3 +256,21 @@ func completions(root *cobra.Command) *cobra.Command {
256256
logrus.Debug("Completions (bash/zsh) commands added")
257257
return c
258258
}
259+
260+
/*
261+
* deduplicate a slice of strings, keeping the order of the elements
262+
*/
263+
func deduplicate(input []string) []string {
264+
var output []string
265+
unique := map[string]interface{}{}
266+
for _, i := range input {
267+
unique[i] = new(interface{})
268+
}
269+
for _, i := range input {
270+
if _, ok := unique[i]; ok {
271+
output = append(output, i)
272+
delete(unique, i)
273+
}
274+
}
275+
return output
276+
}

0 commit comments

Comments
 (0)