From fe9cf673a23007d97d2cd6e2c96426d776c62aa6 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 21 Sep 2014 21:09:21 -0700 Subject: [PATCH] Add --right-prompt flag to read Add a flag to read to allow for setting the right prompt command in addition to the existing support for setting the prompt command. Fixes #1698. --- builtin.cpp | 12 +++++++++++- doc_src/read.txt | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin.cpp b/builtin.cpp index 1927b5cab..36be7e9b6 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -2310,6 +2310,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv) int i, argc = builtin_count_args(argv); int place = ENV_USER; const wchar_t *prompt = DEFAULT_READ_PROMPT; + const wchar_t *right_prompt = L""; const wchar_t *commandline = L""; int exit_res=STATUS_BUILTIN_OK; const wchar_t *mode_name = READ_MODE_NAME; @@ -2350,6 +2351,10 @@ static int builtin_read(parser_t &parser, wchar_t **argv) L"prompt", required_argument, 0, 'p' } , + { + L"right-prompt", required_argument, 0, 'R' + } + , { L"command", required_argument, 0, 'c' } @@ -2388,7 +2393,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv) int opt = wgetopt_long(argc, argv, - L"xglUup:c:hm:n:saz", + L"xglUup:R:c:hm:n:saz", long_options, &opt_index); if (opt == -1) @@ -2431,6 +2436,10 @@ static int builtin_read(parser_t &parser, wchar_t **argv) prompt = woptarg; break; + case L'R': + right_prompt = woptarg; + break; + case L'c': commandline = woptarg; break; @@ -2556,6 +2565,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv) reader_push(mode_name); reader_set_left_prompt(prompt); + reader_set_right_prompt(right_prompt); if (shell) { reader_set_complete_function(&complete); diff --git a/doc_src/read.txt b/doc_src/read.txt index 79335a794..33829070c 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -23,6 +23,8 @@ The following options are available: - `-p PROMPT_CMD` or `--prompt=PROMPT_CMD` uses the output of the shell command `PROMPT_CMD` as the prompt for the interactive mode. The default prompt command is set_color green; echo read; set_color normal; echo "> ". +- `-R RIGHT_PROMPT_CMD` or `--right-prompt=RIGHT_PROMPT_CMD` uses the output of the shell command `RIGHT_PROMPT_CMD` as the right prompt for the interactive mode. There is no default right prompt command. + - `-s` or `--shell` enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. - `-u` or `--unexport` prevents the variables from being exported to child processes (default behaviour).