I’m getting more and more familiar with the GIT workflow, which goes kinda like this:

git checkout -b topicbranchX
git add somefile
git commit -m"commit message"
git pull
git rebase master
git push

Unfortunately this means that you’ll end up with a bunch of branches (which you can delete once they get pulled into origin/master) but I keep forgetting what branch I currently have checked out. I’ve seen bash prompts that show the current branch and I decided to do something similar for TCC/LE.

/*
@cl "/Tp%~f0" /nologo /GS- /link /SUBSYSTEM:console /nodefaultlib /entry:_main kernel32.lib
@goto :EOF
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
const WCHAR root[] = L"..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\.git\\HEAD";
int __stdcall _main() {
  int offset = sizeof(root)/2 - 10;
  while (offset >= 0) {
    HANDLE h = CreateFileW(root + offset, GENERIC_READ, FILE_SHARE_READ, NULL,
      OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (h != INVALID_HANDLE_VALUE) {
      char buf[64];
      DWORD read = 0;
      if (ReadFile(h, buf, sizeof(buf), &read, NULL) && read > 16) {
        DWORD off = 0;
        DWORD len = 7;            // show 7 hex digits
        if ((int&)buf[0] == ':fer') {
          off = 16;               // skip ref: refs/heads/
          len = read - off ;     // keep LF
        }
        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf + off, len, NULL, NULL);
      }
      return 13 - offset / 3;
    }
    offset -= 3;
  }
  return 0;
}

What’s fun about this file is that you can save it as “gb.cmd”. When you then enter “gb” on the command line, it will actually invoke the C compiler (remember to run vcvars32) to generate the gb.exe. Next time, the exe will be invoked instead.

This is the final prompt:

prompt %%@exec[@gb.exe]$e[1m$P$e[0m$_$+$g