From: hwangcc23 Date: Thu, 9 Jul 2015 14:25:50 +0000 (+0800) Subject: Display which config is used in --more_version X-Git-Tag: 4.11~80^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F1786%2Fhead;p=i3%2Fi3 Display which config is used in --more_version In the output of i3 --moreversion, display the path of the used config and its last modified time. --- diff --git a/docs/ipc b/docs/ipc index 837b4d98..ed8f5587 100644 --- 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 diff --git a/src/display_version.c b/src/display_version.c index 6ece3f74..c82610ed 100644 --- a/src/display_version.c +++ b/src/display_version.c @@ -16,20 +16,25 @@ #include #include #include +#include #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; diff --git a/src/ipc.c b/src/ipc.c index 9d3cf363..51a3d223 100644 --- 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;