From 573916e5e29163f155d07dfd67372ab68686c98e Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 6 Jan 2017 21:14:29 -0800 Subject: [PATCH] ensure CMD_DURATION can be used in prompts A third-party plugin noticed that using `$CMD_DURATION` in the prompt causes problems when combined with the recent changes to tighten up parsing of strings meant to be integer values. This fixes the problem by ensuring the var is defined before the first interactive command is run. See https://github.com/fisherman/dartfish/issues/7 --- src/reader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 5902c6d14..77dbbe4ec 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -72,6 +72,10 @@ #include "util.h" #include "wutil.h" // IWYU pragma: keep +// Name of the variable that tells how long it took, in milliseconds, for the previous +// interactive command to complete. +#define ENV_CMD_DURATION L"CMD_DURATION" + /// Maximum length of prefix string when printing completion list. Longer prefixes will be /// ellipsized. #define PREFIX_MAX_LEN 9 @@ -768,6 +772,11 @@ static void exec_prompt() { void reader_init() { VOMIT_ON_FAILURE(pthread_key_create(&generation_count_key, NULL)); + // Ensure this var is present even before an interactive command is run so that if it is used + // in a function like `fish_prompt` or `fish_right_prompt` it is defined at the time the first + // prompt is issued. + env_set(ENV_CMD_DURATION, L"0", ENV_UNEXPORT); + // Save the initial terminal mode. tcgetattr(STDIN_FILENO, &terminal_mode_on_startup); @@ -1928,8 +1937,6 @@ bool reader_get_selection(size_t *start, size_t *len) { return result; } -#define ENV_CMD_DURATION L"CMD_DURATION" - void set_env_cmd_duration(struct timeval *after, struct timeval *before) { time_t secs = after->tv_sec - before->tv_sec; suseconds_t usecs = after->tv_usec - before->tv_usec;