mayChangeCwdOrGit function
Whether line could change the working directory or git state, and thus
warrants a prompt refresh (the marker).
Returns false only for a single simple command (no shell operators, not a
cd) whose program is a known read-only command — including read-only git
subcommands. Everything else is treated as state-changing.
Implementation
bool mayChangeCwdOrGit(String line) {
final lineTrimmed = line.trim();
if (lineTrimmed.isEmpty) return false;
final tokens = _significantTokens(line, lineTrimmed);
if (tokens.isEmpty) return false; // empty line changes nothing.
if (_shellOperators.hasMatch(line)) return true;
final program = _basename(tokens.first);
if (program == 'cd') return true;
if (program == 'git') {
final sub = _firstGitSubcommand(tokens.skip(1));
if (sub == 'config') {
// `git config --get …` is read-only; a bare/setting form may change state.
return !tokens.contains('--get') &&
!tokens.contains('--list') &&
!tokens.contains('-l');
}
return !_readOnlyGit.contains(sub);
}
return !_readOnly.contains(program);
}