My current PS1 looks like this:
I'd like to add an invisible timestamp to it, so I can select/highlight it with the cursor when I want to see what time a command ran, but not clutter my normal view.
╭dotfiles 10:24:01 ╰(ivan)•
Right now I have:
Assuming my background color is black, I could use the ANSI color code for black (
\033[0;30m) to print the timestamp invisibly:
PS1='╭\033[1m\W\033[0m \033[0;30m\t\033[0m\n╰(\u)• '
But my background is not always black -- I have a couple color-schemes I switch between.
Ideally, I'd like to dynamically grab the background color from the terminal, but is this possible/feasible? Or maybe there's another approach I could take?
It was rightly pointed out that the ANSI color codes should be enclosed between
\]. So the above settings should actually be:
PS1='╭\[\033[1m\]\W\[\033[0m\] \[\033[0;30m\]\t\[\033[0m\]\n╰(\u)• '