diff --git a/kittens/choose_files/main.py b/kittens/choose_files/main.py index cd4565493..165fc7465 100644 --- a/kittens/choose_files/main.py +++ b/kittens/choose_files/main.py @@ -18,14 +18,14 @@ map = definition.add_map mma = definition.add_mouse_map agr('scan', 'Scanning the filesystem') -opt('+modify_score', r'(^|/)\.[^/]+(/|$) *= 0.5', add_to_default=True, long_text=''' +opt('+modify_score', r'(^|/)\.[^/]+(/|$) *= 0.1', add_to_default=True, long_text=''' Modify the score of items matching the specified regular expression (matches against the absolute path). Can be used to make certain files and directories less or more prominent in the results. Can be specified multiple times. The default includes rules to reduce the score of hidden items and -items in some well known cache folder names. +items in some well known cache folder names. Only applies when some actual search expression is provided. The syntax is :code:`regular-expression operator value`. Supported operators are: :code:`*=, +=, -=, /=`. ''') -opt('+modify_score', '(^|/)__pycache__(/|$) *= 0.5', add_to_default=True) +opt('+modify_score', '(^|/)__pycache__(/|$) *= 0.1', add_to_default=True) egr() def main(args: list[str]) -> None: diff --git a/kittens/choose_files/scan.go b/kittens/choose_files/scan.go index fb8f2b079..2613c11a3 100644 --- a/kittens/choose_files/scan.go +++ b/kittens/choose_files/scan.go @@ -192,15 +192,15 @@ func (sc *ScanCache) scan(root_dir, search_text string, score_patterns []ScorePa patterns = patterns[1:] } } - matches := sc.scan_dir(root_dir, patterns, nil, 0) - for _, ri := range matches { + ans = sc.scan_dir(root_dir, patterns, nil, 0) + for _, ri := range ans { ri.score = get_modified_score(ri.abspath, ri.score, score_patterns) } - if search_text == "" { - ans = sort_items_without_search_text(matches) - return + has_search_text := search_text != "" && search_text != "/" + if !has_search_text { + return sort_items_without_search_text(ans) } - slices.SortStableFunc(matches, func(a, b *ResultItem) int { + slices.SortStableFunc(ans, func(a, b *ResultItem) int { ans := cmp.Compare(b.score, a.score) if ans == 0 { ans = cmp.Compare(len(a.text), len(b.text)) @@ -210,7 +210,7 @@ func (sc *ScanCache) scan(root_dir, search_text string, score_patterns []ScorePa } return ans }) - return matches + return } func (h *Handler) get_results() (ans []*ResultItem, in_progress bool) {