Compare commits
	
		
			1 Commits
		
	
	
		
			5f2c5b58da
			...
			34965bb98d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 34965bb98d | 
							
								
								
									
										14
									
								
								git-prompt.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								git-prompt.c
									
									
									
									
									
								
							@ -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)) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user