I want to have really complex prompt. It should contains login, computer name, date, time, working directory, result of last command and new line symbol. I want to color each item as well. So I inserted into my .bashrc
some kind of monster like this one:
# login and computer name
PS1='[\e[1;37m\]\u\e[m\]@\e[1;32m\]\h\e[m\]] '
# date, time and working directory
PS1=$PS1'[\e[1;34m\]\D{%Y-%m-%d} \e[1;35m\]\t\e[m\]] \e[1;33m\]\w\e[m\] '
# result of last command and command prompt in new line
PS1=$PS1'\e[1;31m\]${?#0}\e[m\]\n \e[1;36m\]\$\e[m\] '
I do know it is terrible solution, but I have too little experience with bash to improve this. But this is not the only one problem.
$ aaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bash: bbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: command not found...
After the last a
I pressed Home
key, but visual caret didn't go to the beginning of the command. As you can see, actual caret went to the beginning. Why this occurred? How can I improve my command prompt in my .bashrc
?
Update:
After using @Groxxda advice, I've got one another problem. My .bashrc
PS1
definition looks like this one. Described issue doesn't occur now. But if in my command history I have ls
and before this I have cat script.sh
, and if I push arrow up twice, I have got command like cat scls
and buffer has only two signs (only ls
). Why this occurs? How can I manage this?
\[
\]
escapes. This tells bash that the content between does not print visible characters. You should put them around the color codes..bashrc
PS1 definition looks like this one: pastebin.com/EZDn6VkP. Described issue doesn't occurs now. But if in my command history I havels
and before this I havecat script.sh
, and if I push arrow twice, I have got command likecat scls
and buffer has only two signs (onlyls
). Why this occurs? How can I manage this?\[…\]
.