Welcome to little lamb

Code » ssp » commit d23d928

add/edit/rename: Show "new" entry afterwards

author Olivier Brunel
2023-04-18 17:13:18 UTC
committer Olivier Brunel
2023-04-19 07:44:23 UTC
parent e3268bf88cf21d80a60b411fb5c11a8c142def73

add/edit/rename: Show "new" entry afterwards

src/include/ssp.h +1 -0
src/ssp/add.c +3 -0
src/ssp/edit.c +3 -0
src/ssp/rename.c +3 -0
src/ssp/ssp.c +9 -0

diff --git a/src/include/ssp.h b/src/include/ssp.h
index ba8f30f..d938fed 100644
--- a/src/include/ssp.h
+++ b/src/include/ssp.h
@@ -65,6 +65,7 @@ struct otp
 
 /* ssp.c */
 int exitcode_from_errno(int e);
+int run_command(const char *name, int argc, const char *argv[], const char *env[], void *ctx);
 ssize_t unesc(char *dst, size_t dlen, const char *sce, size_t slen);
 const char *get_entry_name(const char *s, struct ssp *ctx);
 
diff --git a/src/ssp/add.c b/src/ssp/add.c
index b8ba645..8ece1a3 100644
--- a/src/ssp/add.c
+++ b/src/ssp/add.c
@@ -156,5 +156,8 @@ add_main(int argc, const char *argv[], const char *env[], const char usage[], vo
     out("Adding entry ", ESC, entry, ESC, "... ");
     rebuild_db(NULL, entry, p, ctx);
 
+    const char *av[] = { NULL, entry };
+    run_command("show", sizeof(av) / sizeof(*av), av, env, ctx);
+
     return 0;
 }
diff --git a/src/ssp/edit.c b/src/ssp/edit.c
index 7f7d796..3ba118b 100644
--- a/src/ssp/edit.c
+++ b/src/ssp/edit.c
@@ -203,5 +203,8 @@ edit_main(int argc, const char *argv[], const char *env[], const char usage[], v
     out("Editing entry ", ESC, entry, ESC, "... ");
     rebuild_db(entry, entry, p, ctx);
 
+    const char *av[] = { NULL, entry };
+    run_command("show", sizeof(av) / sizeof(*av), av, env, ctx);
+
     return 0;
 }
diff --git a/src/ssp/rename.c b/src/ssp/rename.c
index 656bada..7053bd1 100644
--- a/src/ssp/rename.c
+++ b/src/ssp/rename.c
@@ -44,5 +44,8 @@ rename_main(int argc, const char *argv[], const char *env[], const char usage[],
     out("Renaming ", ESC, entry, ESC, " to ", ESC, new, ESC, "...");
     rebuild_db(entry, new, db_otp(ctx), ctx);
 
+    const char *av[] = { NULL, new };
+    run_command("show", sizeof(av) / sizeof(*av), av, env, ctx);
+
     return 0;
 }
diff --git a/src/ssp/ssp.c b/src/ssp/ssp.c
index 80a433d..eba3fff 100644
--- a/src/ssp/ssp.c
+++ b/src/ssp/ssp.c
@@ -36,6 +36,15 @@ exitcode_from_errno(int e)
     }
 }
 
+int
+run_command(const char *name, int argc, const char *argv[], const char *env[], void *ctx)
+{
+    for (struct command **c = commands; *c; ++c)
+        if (!strcmp((*c)->name, name))
+            return (*c)->main(argc, argv, env, "", ctx);
+    return -1;
+}
+
 ssize_t
 unesc(char *dst, size_t dlen, const char *sce, size_t slen)
 {