3

Here is my PS1:

export PS1='\u@\h:\w\$ '

Which looks like this:

user@ubuntu:~/ $

I have bound Alt+{Left,Right} Arrow to command that change the current working directory:

bind -x '"\e[1;3D":pushd . > /dev/null && cd ..'
bind -x '"\e[1;3C":popd > /dev/null'

This works, but the current working directory in PS1 is not evaluated since no carriage return is entered. Is there a way to force bash to reevaluate PS1 in line?

Luke Skywalker
  • 1,464
  • 3
  • 17
  • 35

1 Answers1

0

Following along with the accepted answer of in-bash-how-do-i-bind-function-key-to-a-command, it looks like removing the -x and adding a \n at the end should do it:

bind '"\e[1;3D":"pushd . >/dev/null && cd .. && echo\n"'
bind '"\e[1;3C":"popd > /dev/null && echo -n\n"'
Community
  • 1
  • 1
xxfelixxx
  • 6,512
  • 3
  • 31
  • 38
  • It does not really do what I want because it displays the command and then add a carriage return. But I'd like to do that without displaying the command and add a carriage return. I'd like to make the change inline for aesthetic reasons. – Luke Skywalker Oct 13 '16 at 09:18
  • Thanks, fixed. I could not find any other way of forcing bash to reissue the $PS1 prompt. – xxfelixxx Oct 13 '16 at 09:20
  • me neither, that's why I am asking ;) – Luke Skywalker Oct 13 '16 at 09:21