I'm using Mac. I want to set PS1 variable to get current time at the end of line in command line prompt. Like this:
or this:
But, unfortunately, I can't get what I want through following configuration:
CYAN="\[$(tput setaf 6)\]"
GREEN="\[$(tput setaf 2)\]"
BLUE="\[$(tput setaf 4)\]"
YELLOW="\[$(tput setaf 3)\]"
export PS1="$GREEN\u$BLUE@$CYAN\h $YELLOW\w\[$(tput cuf $(($(tput cols)-33)))\]$CYAN\[$(date +%H:%M)\]\n\\$ "
It seems that I need to get the current position of cursor and do some computations based on the coordinate of the position, but I don't know how to get it. Is anyone can help?