searchBranches top-level property
搜索分支生成器
Implementation
final FigGenerator searchBranches = FigGenerator(
script: ['git', 'branch', '--no-color'],
postProcess: (String out, [List<String>? tokens]) {
final output = filterMessages(out);
if (output.startsWith('fatal:')) {
return <FigSuggestion>[];
}
return output
.split('\n')
.where((elm) => elm.trim().isNotEmpty)
.map<FigSuggestion>((elm) {
final trimmedElm = elm.trim();
final parts = RegExp(r'\S+')
.allMatches(trimmedElm)
.map((m) => m.group(0)!)
.toList();
if (parts.isNotEmpty && parts.length > 1) {
if (parts[0] == '*') {
// 当前分支
return FigSuggestion(
name: trimmedElm.replaceAll('*', '').trim(),
description: 'Current branch',
icon: '⭐️',
priority: 100,
);
} else if (parts[0] == '+') {
// 在其他工作树中检出的分支
final name = trimmedElm.replaceAll('+', '').trim();
return FigSuggestion(
name: name,
description: 'Branch',
icon: 'fig://icon?type=git',
);
}
}
return FigSuggestion(
name: trimmedElm,
description: 'Branch',
icon: 'fig://icon?type=git',
);
}).toList();
},
);