]> git.sur5r.net Git - i3/i3/commitdiff
Display which config is used in --more_version 1786/head
authorhwangcc23 <hwangcc@csie.nctu.edu.tw>
Thu, 9 Jul 2015 14:25:50 +0000 (22:25 +0800)
committerhwangcc23 <hwangcc@csie.nctu.edu.tw>
Fri, 10 Jul 2015 14:54:25 +0000 (22:54 +0800)
In the output of i3 --moreversion,
display the path of the used config and its last modified time.

docs/ipc
src/display_version.c
src/ipc.c

index 837b4d98606d56173dd1b06b93902d5ed03b6089..ed8f55872ac49bcc79afe65f207dc164f76cccd0 100644 (file)
--- a/docs/ipc
+++ b/docs/ipc
@@ -582,11 +582,14 @@ human_readable (string)::
        build date and branch name. When you need to display the i3 version to
        your users, use the human-readable version whenever possible (since
        this is what +i3 --version+ displays, too).
+loaded_config_file_name (string)::
+       The current config path.
 
 *Example:*
 -------------------
 {
    "human_readable" : "4.2-169-gf80b877 (2012-08-05, branch \"next\")",
+   "loaded_config_file_name" : "/home/hwangcc23/.i3/config",
    "minor" : 2,
    "patch" : 0,
    "major" : 4
index 6ece3f742dde32f9916b66a061661fee0e86b6d5..c82610ed38ff2856975a8ae37838b947a4f23e1b 100644 (file)
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <fcntl.h>
+#include <time.h>
 #include "all.h"
 
-static bool human_readable_key;
-static char *human_readable_version;
+static bool human_readable_key, loaded_config_file_name_key;
+static char *human_readable_version, *loaded_config_file_name;
 
 static int version_string(void *ctx, const unsigned char *val, size_t len) {
     if (human_readable_key)
         sasprintf(&human_readable_version, "%.*s", (int)len, val);
+    if (loaded_config_file_name_key)
+        sasprintf(&loaded_config_file_name, "%.*s", (int)len, val);
     return 1;
 }
 
 static int version_map_key(void *ctx, const unsigned char *stringval, size_t stringlen) {
     human_readable_key = (stringlen == strlen("human_readable") &&
                           strncmp((const char *)stringval, "human_readable", strlen("human_readable")) == 0);
+    loaded_config_file_name_key = (stringlen == strlen("loaded_config_file_name") &&
+                                   strncmp((const char *)stringval, "loaded_config_file_name", strlen("loaded_config_file_name")) == 0);
     return 1;
 }
 
@@ -104,6 +109,21 @@ void display_running_version(void) {
 
     printf("\rRunning i3 version: %s (pid %s)\n", human_readable_version, pid_from_atom);
 
+    if (loaded_config_file_name) {
+        struct stat sb;
+        time_t now;
+        char mtime[64];
+        printf("Loaded i3 config: %s", loaded_config_file_name);
+        if (stat(loaded_config_file_name, &sb) == -1) {
+            printf("\n");
+            ELOG("Cannot stat config file \"%s\"\n", loaded_config_file_name);
+        } else {
+            strftime(mtime, sizeof(mtime), "%c", localtime(&(sb.st_mtime)));
+            time(&now);
+            printf(" (Last modified: %s, %.f seconds ago)\n", mtime, difftime(now, sb.st_mtime));
+        }
+    }
+
 #ifdef __linux__
     size_t destpath_size = 1024;
     ssize_t linksize;
index 9d3cf363085c7473585e40dcf24a04183d69276c..51a3d22315e625945f0e2765a033cfb83ee6d20c 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -814,6 +814,9 @@ IPC_HANDLER(get_version) {
     ystr("human_readable");
     ystr(i3_version);
 
+    ystr("loaded_config_file_name");
+    ystr(current_configpath);
+
     y(map_close);
 
     const unsigned char *payload;