fullMarker method

  1. @override
String fullMarker(
  1. CwdMarker marker
)
override

The full marker command: reports cwd plus git branch/status and privilege.

Implementation

@override
String fullMarker(CwdMarker marker) {
  final (a, b) = marker.tokenHalves;
  // Compute the fields in PowerShell: branch via git, status counts mirror the
  // POSIX awk (+staged ~modified ?untracked), privilege = 'root' when elevated.
  // Unset fields are $null so they render as empty (matching the POSIX marker).
  // Pure-PowerShell (no Dart interpolation), so a raw string is safe here.
  const compute =
      r'''$o=[Console]::Out;$br=("$(git rev-parse --abbrev-ref HEAD 2>$null)").Trim();$st=@(git status --porcelain 2>$null);$s=0;$m=0;$u=0;foreach($l in $st){if($l -match '^\?\?'){$u++}else{if($l.Length -ge 1 -and $l[0] -ne ' '){$s++};if($l.Length -ge 2 -and $l[1] -ne ' '){$m++}}};$stat=if($s+$m+$u -gt 0){"+$s ~$m ?$u"}else{$null};$pv=if(([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){'root'}else{$null};''';
  // Emit one line: token (split halves) + cwd, then tab-separated fields and a
  // trailing newline. Tabs are [char]9, the newline [char]10.
  final write =
      "\$o.Write('$a'+'$b'+\$PWD.Path"
      r'+[char]9+$br+[char]9+$stat+[char]9+$pv+[char]10);$o.Flush()';
  return '$compute$write';
}