One-liner to mimic the original __git_ps1 shell function, git / sh

PHOTO EMBED

Sat Jan 08 2022 06:27:13 GMT+0000 (Coordinated Universal Time)

Saved by @juliyvchirkov #sh #git #ps1 #shell

#!/usr/bin/env sh

__git_ps1() {
    git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'
}
content_copyCOPY

If one is missing the original *__git_ps1* function from [@git/git](https://github.com/git/git) package, this one-liner can be utilized as temporary solution. Just like the original, it prints current branch name like *main*, *dev* etc. or nothing, if current directory is outside of any git tree see [@git/git/.../git-prompt.sh](https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh)
https://gist.github.com/juliyvchirkov/883a050c34e23f4b4fba6ecaeb050c3b