command property
String
get
command
The shell command (without trailing newline) to enqueue after a command.
Splitting token into two printf args keeps the full token out of the
literal command text while still emitting it intact at runtime.
The marker line carries tab-separated fields after the token: $PWD, the
git branch (empty outside a repo), a compact status (+staged ~modified ?untracked, empty when clean), and a privilege label (root when euid 0).
Git branch names cannot contain tabs or spaces, so \t is a safe delimiter.
Inline command substitution is used so the remote shell's environment is
not polluted; the raw-string parts keep Dart from interpreting the shell's
$, \, and quotes.
Implementation
String get command {
final (a, b) = tokenHalves;
const pwd = r'"$PWD"';
const branch = r'"$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"';
const status =
r'''"$(git status --porcelain 2>/dev/null | awk 'BEGIN{s=0;m=0;u=0}/^\?\?/{u++;next}{if(substr($0,1,1)!=" ")s++;if(substr($0,2,1)!=" ")m++}END{if(s+m+u>0)printf "+%d ~%d ?%d",s,m,u}')"''';
const priv = r'''"$([ "$(id -u 2>/dev/null)" = 0 ] && echo root)"''';
return "printf '%s%s%s\\t%s\\t%s\\t%s\\n' '$a' '$b' $pwd $branch $status $priv";
}