here is a plugin, so by pressing a keyboard shortcut the results are sorted:
The plugin:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sublime, sublime_plugin, unicodedata
import os, re
import datetime as dt
class sort_searchresults_github_thread(sublime_plugin.TextCommand):
def run(self, edit):
print('hello')
point = self.view.sel()[0].b
body = self.view.substr(sublime.Region(0, self.view.size()))
file_results_listofdicts = []
results = body.split('\n\n')
file_pattern = r'.*' # here you can specify patterns for the path line, e. g. '\.txt'
filenumber_pattern = r'Searching \d{1,9} files for .*'
matchnumber_pattern = r'\d{1,9} matches across \d{1,9} files'
end_str = ''
for result in results:
if re.search(filenumber_pattern, result):
match = re.search(filenumber_pattern, result)
result = match.group()
print("filenumber found:", result)
end_str = end_str + result
elif re.search(matchnumber_pattern, result):
match = re.search(matchnumber_pattern, result)
result = match.group()
print("matchnumber found:", result)
end_str = f'{end_str} | {result}'
elif re.search(file_pattern, result):
matches = re.findall(file_pattern, result)
path = matches[0]
context = ''
for match in matches[1:]:
if not match == '':
context += f'{match}\n'
file_results_listofdicts.append({'path': path, 'context': context.rstrip()})
sorted_listofdicts = sorted(file_results_listofdicts, key=lambda x: x['path'])
region = sublime.Region(0, self.view.size())
self.view.erase(edit, region)
for result_dict in sorted_listofdicts:
self.view.insert(edit, 0, f"{result_dict['path']}\n{result_dict['context']}\n\n") # neueste Ergenbisse oben
#self.view.insert(edit, self.view.size(), f"{result_dict['result']}\n\n") # neueste Ergenbisse unten
self.view.insert(edit, 0, f"{end_str}\n\n")
on a mac save the plugin in:
/Users/your_username/Library/Application Support/Sublime Text/Packages/User/plugin_sort_searchresults_github_thread.py
key binding:
{ "keys": ["alt+s"], "command": "sort_searchresults_github_thread" },
If you hit ‘cmd+f’ after the sorting, it even highlights your searchterm, so you get the same result as in sublimetext 3.