bash-git-prompt icon indicating copy to clipboard operation
bash-git-prompt copied to clipboard

Adding things to existing PS1 string

Open pankajpatel opened this issue 9 years ago • 7 comments

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]
👍  

pankajpatel avatar Sep 14 '16 17:09 pankajpatel

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.

robertg042 avatar Sep 23 '16 01:09 robertg042

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.

MarioHoberg avatar Sep 01 '17 10:09 MarioHoberg

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?

Skillzore avatar Nov 20 '17 09:11 Skillzore

I moved on to use zsh with oh-my-zsh plugin and it works like charm.

pankajpatel avatar Nov 21 '17 09:11 pankajpatel

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. :)

helmesjo avatar Aug 22 '18 19:08 helmesjo

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.

nlowe avatar Feb 25 '19 22:02 nlowe

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.

romcyncynatus avatar Apr 17 '19 12:04 romcyncynatus