optimise
instead of putting each part of the face into an array we just print it out to the console :)
This commit is contained in:
34
XD.c
34
XD.c
@ -9,8 +9,6 @@
|
||||
#include <git2.h>
|
||||
#endif
|
||||
|
||||
enum face { EYES, NOSE, MOUTH };
|
||||
|
||||
void
|
||||
l(const char *fmt, ...)
|
||||
{
|
||||
@ -156,7 +154,6 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, code = -1;
|
||||
char face[] = { ':', 0, '|' };
|
||||
|
||||
/* print version information */
|
||||
for (i = 1; i < argc; i++) {
|
||||
@ -177,23 +174,26 @@ main(int argc, char *argv[])
|
||||
if (git_ok) {
|
||||
/* change the eyes depending on the current git repo's status */
|
||||
if (has_stashes(repo)) {
|
||||
face[EYES] = '8'; /* goggle eyes if we have some stashed changes */
|
||||
printf("8"); /* goggle eyes if we have some stashed changes */
|
||||
} else if (git_repository_is_empty(repo)) {
|
||||
face[EYES] = 'B'; /* sunglasses if we're in a new repo with no HEAD */
|
||||
printf("B"); /* sunglasses if we're in a new repo with no HEAD */
|
||||
} else {
|
||||
face[EYES] = ';'; /* wink when we're in a git repo */
|
||||
printf(";"); /* wink when we're in a git repo */
|
||||
}
|
||||
|
||||
/* change the nose depending on the current git repo's status */
|
||||
if (has_staged(repo)) {
|
||||
face[NOSE] = '*'; /* change to broken nose for staged changes */
|
||||
printf("*"); /* change to broken nose for staged changes */
|
||||
} else if (has_untracked(repo)) {
|
||||
face[NOSE] = '^'; /* add a little nose when there are untracked changes in the repo */
|
||||
printf("^"); /* add a little nose when there are untracked changes in the repo */
|
||||
} else if (git_repository_head_detached(repo)) {
|
||||
face[NOSE] = '-'; /* add a minus nose when the HEAD is detached */
|
||||
printf("-"); /* add a minus nose when the HEAD is detached */
|
||||
}
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (1) {
|
||||
printf(":");
|
||||
}
|
||||
|
||||
/* get exit code from user args */
|
||||
if (argv[1]) {
|
||||
@ -203,20 +203,18 @@ main(int argc, char *argv[])
|
||||
/* change mouth based on exit code */
|
||||
if (code >= 0) {
|
||||
switch (code) {
|
||||
case 0: face[MOUTH] = ')'; break; /* all good */
|
||||
case 130: face[MOUTH] = 'O'; break; /* Ctrl-c pressed (SIGTERM) */
|
||||
case 126: face[MOUTH] = 'P'; break; /* permission denied */
|
||||
case 127: face[MOUTH] = '/'; break; /* command not found */
|
||||
default: face[MOUTH] = '('; break; /* all other codes (usually the program saying it has failed) */
|
||||
case 0: printf(")"); break; /* all good */
|
||||
case 130: printf("O"); break; /* Ctrl-c pressed (SIGTERM) */
|
||||
case 126: printf("P"); break; /* permission denied */
|
||||
case 127: printf("/"); break; /* command not found */
|
||||
default: printf("("); break; /* all other codes (usually the program saying it has failed) */
|
||||
}
|
||||
} else {
|
||||
face[MOUTH] = '|'; /* no code info */
|
||||
printf("|"); /* no code info */
|
||||
}
|
||||
|
||||
#ifdef GIT
|
||||
git_repository_free(repo);
|
||||
git_libgit2_shutdown();
|
||||
#endif
|
||||
|
||||
printf("%c%c%c", face[EYES], face[NOSE], face[MOUTH]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user