My .bashrc has the following:
# Alt+L lists current directory
bind -x "\"\el\":ls -ltrF --color=auto;"
# trap commands and echo them to xterm titlebar.
trap 'echo -ne "\033]0;$BASH_COMMAND - $USER@${HOSTNAME}>$(pwd)\007"' DEBUG
Demo of the problem:
bash-4.2$ [Alt+L] #works
total 0
-rw-rw-r-- 1 me 1234 0 Aug 3 07:11 foo
-rw-rw-r-- 1 me 1234 0 Aug 3 07:11 bar
bash-4.2$ ls -ltr #fails first time
bash: -ltr: command not found
bar foo
bash-4.2$ ls -ltr #works second time
total 0
-rw-rw-r-- 1 me 1234 0 Aug 3 07:11 foo
-rw-rw-r-- 1 me 1234 0 Aug 3 07:11 bar
As you can see, the ls
command fails the first time after executing the key binding. I believe it has to do with the trap. Removing the trap fixes the issue.
Is there any way to fix this without removing the trap?