classifyCommand function
Search/read/list classification for UI display.
Implementation
({bool isSearch, bool isRead, bool isList}) classifyCommand(String command) {
const searchCmds = {
'find',
'grep',
'rg',
'ag',
'ack',
'locate',
'which',
'whereis',
'fd',
'fzf',
};
const readCmds = {
'cat',
'head',
'tail',
'less',
'more',
'wc',
'stat',
'file',
'strings',
'jq',
'yq',
'awk',
'cut',
'sort',
'uniq',
'tr',
'xxd',
'hexdump',
'od',
};
const listCmds = {'ls', 'tree', 'du', 'df', 'lsof', 'lsblk'};
final segments = command.split(RegExp(r'\s*[|;&]\s*'));
if (segments.isEmpty) {
return (isSearch: false, isRead: false, isList: false);
}
var isSearch = true;
var isRead = true;
var isList = true;
for (final seg in segments) {
final base = seg.trim().split(RegExp(r'\s+')).first;
if (base.isEmpty) continue;
if (!searchCmds.contains(base)) isSearch = false;
if (!readCmds.contains(base)) isRead = false;
if (!listCmds.contains(base)) isList = false;
}
return (isSearch: isSearch, isRead: isRead, isList: isList);
}