mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 13:23:09 +00: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
1 changed files with 9 additions and 2 deletions
|
@ -72,6 +72,10 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "wutil.h" // IWYU pragma: keep
|
#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
|
/// Maximum length of prefix string when printing completion list. Longer prefixes will be
|
||||||
/// ellipsized.
|
/// ellipsized.
|
||||||
#define PREFIX_MAX_LEN 9
|
#define PREFIX_MAX_LEN 9
|
||||||
|
@ -768,6 +772,11 @@ static void exec_prompt() {
|
||||||
void reader_init() {
|
void reader_init() {
|
||||||
VOMIT_ON_FAILURE(pthread_key_create(&generation_count_key, NULL));
|
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.
|
// Save the initial terminal mode.
|
||||||
tcgetattr(STDIN_FILENO, &terminal_mode_on_startup);
|
tcgetattr(STDIN_FILENO, &terminal_mode_on_startup);
|
||||||
|
|
||||||
|
@ -1928,8 +1937,6 @@ bool reader_get_selection(size_t *start, size_t *len) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ENV_CMD_DURATION L"CMD_DURATION"
|
|
||||||
|
|
||||||
void set_env_cmd_duration(struct timeval *after, struct timeval *before) {
|
void set_env_cmd_duration(struct timeval *after, struct timeval *before) {
|
||||||
time_t secs = after->tv_sec - before->tv_sec;
|
time_t secs = after->tv_sec - before->tv_sec;
|
||||||
suseconds_t usecs = after->tv_usec - before->tv_usec;
|
suseconds_t usecs = after->tv_usec - before->tv_usec;
|
||||||
|
|
Loading…
Reference in a new issue