How can one modify PS1 to display time in right most corner?
题
Currently it is displayed as follows
export PS1='${white}[\t] ${blue}\W:${red}$(__git_ps1)${white} \$ '
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)]> "
不隶属于 StackOverflow