Compare commits

..

1 Commits

Author SHA1 Message Date
34965bb98d Move entire git-prompt to C 2018-09-11 18:12:45 +01:00

View File

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