Compare commits

..

1 Commits

Author SHA1 Message Date
5f2c5b58da Move entire git-prompt to C 2018-09-11 20:56:27 +01:00

View File

@ -8,11 +8,18 @@
#include <sys/wait.h>
#endif
#ifdef DEBUG
#define check(CONDITION) \
if (CONDITION) { \
fprintf(stderr, "error: %s: %d: %s\n", __FILE__, __LINE__, #CONDITION); \
exit(0); \
}
#else
#define check(CONDITION) \
if (CONDITION) { \
exit(0); \
}
#endif
typedef struct process {
pid_t pid;
@ -78,13 +85,8 @@ char* inttostr(char* buffer, int value) {
}
int main() {
process_t process;
// check we are in a git repo
process = process_open("git rev-parse --git-dir");
check(process_close(process));
// get the current branch name
process = process_open("git symbolic-ref --short HEAD");
process_t process = process_open("git symbolic-ref --short HEAD");
char branch_buf[256] = {};
fread(branch_buf, 1, sizeof(branch_buf), process.out);
if (process_close(process)) {