سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

Is this your output prompt looking for ?

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top