summaryrefslogtreecommitdiffstats
path: root/XD.c
diff options
context:
space:
mode:
Diffstat (limited to 'XD.c')
-rw-r--r--XD.c57
1 files changed, 50 insertions, 7 deletions
diff --git a/XD.c b/XD.c
index 362fe79..5d97a57 100644
--- a/XD.c
+++ b/XD.c
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef ERR
+#include <ctype.h>
+
+#if defined(ERR) || defined(EXPLAIN)
#include <stdarg.h>
#endif
@@ -13,7 +15,7 @@
#define P(X) fwrite(X, 1, 1, stdout)
-#ifdef ERR
+#if defined(ERR) || defined(EXPLAIN)
void
l(const char *fmt, ...)
{
@@ -30,11 +32,23 @@ l(const char *fmt, ...)
fputc('\n', stderr);
}
}
+#endif
+
+#ifdef ERR
#define L(...) l(__VA_ARGS__)
#else
#define L(...)
#endif
+#ifdef EXPLAIN
+static int explain = 0;
+#define E(...) if (explain) { \
+ l(__VA_ARGS__); \
+ } else
+#else
+#define E(...)
+#endif
+
#ifdef GIT
/**
* @brief search all parent directories for a git repo
@@ -225,6 +239,10 @@ main(int argc, char *argv[])
if (argc > 1 && strcmp(argv[1], "-v") == 0) {
printf("XD [number] v%s\n", VERSION);
return 0;
+ #ifdef EXPLAIN
+ } else if (argc > 1 && strcmp(argv[1], "-e") == 0) {
+ explain = 1;
+ #endif
}
#ifdef GIT
@@ -233,19 +251,25 @@ main(int argc, char *argv[])
if ((repo = init_git())) {
/* change the eyes depending on the current git repo's status */
if (has_stashes(repo)) {
+ E("The current git repo has stashed changes.")
P("8"); /* goggle eyes if we have some stashed changes */
} else if (git_repository_is_empty(repo)) {
+ E("This is a new git repo.")
P("B"); /* sunglasses if we're in a new repo with no HEAD */
} else {
+ E("In a git repository.")
P(";"); /* wink when we're in a git repo */
}
/* change the nose depending on the current git repo's status */
if (has_staged(repo)) {
+ E("The're staged changes.")
P("*"); /* change to broken nose for staged changes */
} else if (has_untracked(repo)) {
+ E("There are untracked changes in the repository.")
P("^"); /* add a little nose when there are untracked changes in the repo */
} else if (git_repository_head_detached(repo)) {
+ E("The HEAD is detached.")
P("-"); /* add a minus nose when the HEAD is detached */
}
git_repository_free(repo);
@@ -253,6 +277,7 @@ main(int argc, char *argv[])
} else
#endif
if (1) {
+ E("Not in a git repository.")
P(":");
}
@@ -264,13 +289,31 @@ main(int argc, char *argv[])
/* change mouth based on exit code */
if (code >= 0) {
switch (code) {
- case 0: P(")"); break; /* all good */
- case 130: P("O"); break; /* Ctrl-c pressed (SIGTERM) */
- case 126: P("P"); break; /* permission denied */
- case 127: P("/"); break; /* command not found */
- default: P("("); break; /* all other codes (usually the program saying it has failed) */
+ case 0: /* all good */
+ E("Return code of %d, no errors.", code)
+ P(")");
+ break;
+ case 130: /* Ctrl-c pressed (SIGTERM) */
+ E("Return code of %d, ctrl-c was pressed, or SIGTERM sent.", code)
+ P("O");
+ break;
+ case 126: /* permission denied */
+ E("Return code of %d, permission denied.", code)
+ P("P");
+ break;
+ case 127: /* command not found */
+ E("Return code of %d, command not found.", code)
+ P("/");
+ break;
+ default: /* all other codes (usually the program saying it has failed) */
+ E("Return code of %d, probably an error with the program.", code)
+ P("(");
+ break;
}
} else {
+ E("No code information passed in.")
P("|"); /* no code info */
}
+
+ return code;
}