chore: use go fix to enhance codebase (#29)
This pull request modernizes the codebase by adopting Go 1.21+ features, including built-in functions like min and max, standard library iterators such as strings.SplitSeq and strings.FieldsSeq, utility functions like maps.Copy and slices.Contains, and string manipulation helpers like strings.Cut and strings.CutPrefix. Feedback is provided on a test file where the usage of strings.Builder can be further optimized to avoid unnecessary string allocations during concatenation. `go fix -diff ./...`
This commit is contained in:
@@ -95,8 +95,8 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error
|
||||
}
|
||||
}
|
||||
} else if shellName == "fish" {
|
||||
if strings.HasPrefix(line, "- cmd: ") {
|
||||
cmd = strings.TrimPrefix(line, "- cmd: ")
|
||||
if after, ok := strings.CutPrefix(line, "- cmd: "); ok {
|
||||
cmd = after
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
@@ -128,10 +128,7 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error
|
||||
|
||||
if query == "" {
|
||||
var results []HistResult
|
||||
limit := 100
|
||||
if len(historyCache) < limit {
|
||||
limit = len(historyCache)
|
||||
}
|
||||
limit := min(len(historyCache), 100)
|
||||
|
||||
for i := 0; i < limit; i++ {
|
||||
cmd := historyCache[i]
|
||||
@@ -251,11 +248,11 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error
|
||||
if tI != tJ {
|
||||
return tI < tJ
|
||||
}
|
||||
|
||||
|
||||
if tI == 4 && results[i].FuzzyScore != results[j].FuzzyScore {
|
||||
return results[i].FuzzyScore > results[j].FuzzyScore
|
||||
}
|
||||
|
||||
|
||||
return results[i].ID > results[j].ID
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user