First you may refer to this great post here: Bash bind for better understanding what I am trying to achieve.
I want to achieve that when I hit the enter then update the shell prompt dynamically, now I already had is:
__update_shell_prompt () {
# according what I had done in the terminal regenerate the new shell prompt
# new_shell_prompt
export PS1=$new_shell_prompt
}
bind '"\C-M":"\n__update_shell_prompt\n"'
It works as expected, just after each command I executed it would echo the text __update_shell_prompt
also, like:
I also tried to use the bind
with the -x
option like this:
bind -x '"\C-M":"\n__update_shell_prompt\n"''
Then it doesn't respect the \n
, so it totally doesn't work, if I remove the \n
, it still doesn't work, and bring another serious problem in, the command I tried to execute just remain in the screen and never would get executed, like so: all commands just get stuck there...
So:
- How can I make that don't echo the command text...
- If this is not the right way to achieve this(dynamically update shell prompt upon enter hitting), then how should I do this?