2

Currently it is displayed as follows

export PS1='${white}[\t] ${blue}\W:${red}$(__git_ps1)${white} \$ '

enter image description here

I'd like to experiment with the same set up, but time displayed in the right most corner.

How can i modify my PS1 export for this to happen please?

James Raitsev
  • 92,517
  • 154
  • 335
  • 470

2 Answers2

5

Don't think there's any way to right justify items on the prompt using PS1 in bash (pretty sure there's easy ways to do this in zsh though). You can try writing a function for the PROMPT_COMMAND environment variable and have it print the time with right justify, something along the lines of:

print_pre_prompt ()
{
    TIME=`date +%H:%M`
    printf "\e[1;37m%$(($COLUMNS))s" "${TIME}"
}
PROMPT_COMMAND=print_pre_prompt

Here, the \e[1;37m is the "white" color.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I thinks this limits time display on the current line? If we want to display time in the bottom right corner, we will need the `save_cursor` and `restore_cursor` terminal features. – Henk Langeveld Aug 04 '12 at 20:19
  • Any chance time can appear on the same line as the prompt? – James Raitsev Aug 05 '12 at 16:56
  • @Jam If there it a way, it is beyond my bash-fu. I think even in zsh there's an issue of having it on the same line (the RPS1 built in) because your cursor will start overwriting it given long enough commands – Jon Lin Aug 05 '12 at 17:06
1

Is this your output prompt looking for ?

export PS1="\u@\w [\$(date +%k:%M:%S)]> "

duslabo
  • 1,487
  • 4
  • 20
  • 33