mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 12:41:08 +08:00
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
This commit is contained in:
parent
7a3e0924e0
commit
573916e5e2
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user