Using bind -x to call cd or source a script that changes the directory will not update the prompt to show the new directory after the script finished:
user@host:~$ bind -x '"\C-t": "echo test;cd /"' # I press Ctrl-T test user@host:~$ Prompt still shows ~ as the pwd. Once I press Return or Ctrl-L the prompt shows root as the pwd. Updating the prompt is useful when using the mc-wrapper.sh script for Midnight Commander that changes the bash pwd to the last mc directory when mc exits. There is a similar wrapper for vim for example. Attached patch decodes the prompt string again after running the command passed to bind -x. Regards, Bogdan
--- a/bashline.c 2017-01-20 21:22:01.000000000 +0200 +++ b/bashline.c 2018-08-06 10:05:31.670533840 +0300 @@ -55,6 +55,7 @@ #include "shmbutil.h" #include "trap.h" #include "flags.h" +#include "externs.h" /* decode_prompt_string() */ #if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR) # include <mbstr.h> /* mbschr */ @@ -4066,6 +4067,8 @@ #endif } +extern char *current_readline_prompt; + static int bash_execute_unix_command (count, key) int count; /* ignored */ @@ -4122,6 +4125,11 @@ save_parser_state (&ps); r = parse_and_execute (cmd, "bash_execute_unix_command", SEVAL_NOHIST|SEVAL_NOFREE); restore_parser_state (&ps); + + /* current dir may have changed, decode prompt again */ + FREE (current_readline_prompt); + current_readline_prompt = decode_prompt_string (current_prompt_string); + rl_expand_prompt (current_readline_prompt); v = find_variable ("READLINE_LINE"); l1 = v ? value_cell (v) : 0;