Adding things to existing PS1 string
Hi,
Will it be possible to append the status string [master ↑·1|…1] to existing PS1 string.
My current PS1 looks like
pankaj@DP:hapi-universal-redux (master)
👍
Though it would be cool to transform it to:
pankaj@DP:hapi-universal-redux [master ↑·1|…1]
👍
I don't know if there is an easy way to just append status part of bash-git-prompt to PS1. However, the same result can be achieved with themes. In my case I copied TruncatedPwd_WindowTitle theme file and modified it according to my needs.
AFAIK the main modifications come down to overriding (in a theme file): GIT_PROMPT_START_USER prompt_callback function GIT_PROMPT_END_USER GIT_PROMPT_END_ROOT and other variables as in Default.bgtheme
If this is what fits your needs you can check out my Fixedblackbg.bgtheme.
If this isn't, I guess you can start fiddling with $STATUS from updatePrompt() in gitprompt.sh.
I have the same issue and am wondering if the code could be restructured so that I could get the $STATUS_PREFIX$STATUS string by calling a function from gitprompt.sh.
This is actually what I was expecting this to do, until I saw the example pic. Reformatting the whole prompt feels a bit invasive. I can't believe that there at least isn't an option to only add the status to the existing PS1. I feel like that should have been the cornerstone of a project like this. Me (and many linux users like me) have and love our custom prompts. Completely changing them in all git repositories is not a good design choice. /rantover
So did anyone manage to find a solution/workaround for this?
I moved on to use zsh with oh-my-zsh plugin and it works like charm.
No progress on this? Would be really sweet to just append/insert the git status to current prompt, so that it's consistent with what I already have. :)
This would be useful for me too. I tried to hack around it with GIT_PROMPT_END_USER and the like, but these appear to be cached. If they call a function, they only take the value of the function at definition time, I have to re-source my profile to get them to update.
I added the following to my theme file:
GIT_PROMPT_START_USER="${PS1::-3}"
GIT_PROMPT_START_ROOT="${PS1::-3}"
GIT_PROMPT_END_USER="${ResetColor} $ "
GIT_PROMPT_END_ROOT="${ResetColor} # "
So far it works just fine (I haven't customized my prompt besides bash-git-prompt though). Technically, the lines above remove the last 3 chars from PS1 (space, dollar sign and the dollar's escaping slash), and the result is used as the prompt START part.