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


Sat Jan 08 2022 06:27:13 GMT+0000 (UTC)

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'

If one is missing the original *__git_ps1* function from [@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/.../](