samedi 9 mai 2015

how to get the coordinate of cursor when setting PS1 variable for command line prompt?

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: exmaple 1 or this: example 2

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?

Aucun commentaire:

Enregistrer un commentaire