From 87abcecca605397fb0e21567de40bc7592c374ac Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 14 Jul 2014 23:34:15 +0800 Subject: [PATCH] add command line string as $argv[1] for fish_title --- builtin.cpp | 2 +- reader.cpp | 13 +++++++++---- reader.h | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index 5ab3ea430..7ffcb773b 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -3251,7 +3251,7 @@ static int builtin_fg(parser_t &parser, wchar_t **argv) const wcstring ft = tok_first(j->command_wcstr()); if (! ft.empty()) env_set(L"_", ft.c_str(), ENV_EXPORT); - reader_write_title(); + reader_write_title(j->command_wcstr()); make_first(j); job_set_flag(j, JOB_FOREGROUND, 1); diff --git a/reader.cpp b/reader.cpp index 44a219d5f..336513d80 100644 --- a/reader.cpp +++ b/reader.cpp @@ -902,7 +902,7 @@ bool reader_thread_job_is_stale() return (void*)(uintptr_t) s_generation_count != pthread_getspecific(generation_count_key); } -void reader_write_title() +void reader_write_title(const wchar_t *cmd) { const wchar_t *title; const env_var_t term_str = env_get_string(L"TERM"); @@ -946,7 +946,12 @@ void reader_write_title() } - title = function_exists(L"fish_title")?L"fish_title":DEFAULT_TITLE; + wcstring fish_title = L"fish_title"; + if (cmd) { + fish_title.append(L" "); + fish_title.append(parse_util_escape_string_with_quote(cmd, L'\0')); + } + title = function_exists(L"fish_title")?fish_title.c_str():DEFAULT_TITLE; if (wcslen(title) ==0) return; @@ -1015,7 +1020,7 @@ static void exec_prompt() } /* Write the screen title */ - reader_write_title(); + reader_write_title(0); } void reader_init() @@ -2535,7 +2540,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) if (! ft.empty()) env_set(L"_", ft.c_str(), ENV_GLOBAL); - reader_write_title(); + reader_write_title(cmd.c_str()); term_donate(); diff --git a/reader.h b/reader.h index 3375851a8..cd39915f5 100644 --- a/reader.h +++ b/reader.h @@ -116,8 +116,10 @@ void reader_pop_current_filename(); Write the title to the titlebar. This function is called just before a new application starts executing and just after it finishes. + + \param cmd Command line string passed to \c fish_title if is defined. */ -void reader_write_title(); +void reader_write_title(const wchar_t *cmd); /** Call this function to tell the reader that a repaint is needed, and