diff options
author | Squibid <me@zacharyscheiman.com> | 2024-12-19 12:17:20 -0600 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2024-12-19 12:26:31 -0600 |
commit | 18947be24db926241d6d1f5f89c436ec28c9f18d (patch) | |
tree | c95ee6225044d45a52f3f2a4a8d20746200a1192 /XD.c | |
parent | d3f83e3af836cbe83e2c17d7d24410f6da2031b2 (diff) | |
download | XD-18947be24db926241d6d1f5f89c436ec28c9f18d.tar.gz XD-18947be24db926241d6d1f5f89c436ec28c9f18d.tar.bz2 XD-18947be24db926241d6d1f5f89c436ec28c9f18d.zip |
optimise
instead of putting each part of the face into an array we just
print it out to the console :)
Diffstat (limited to '')
-rw-r--r-- | XD.c | 34 |
1 files changed, 16 insertions, 18 deletions
@@ -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]); } |