fish

PS1 prompt in fish (Friendly Interactive SHell) show git branch


In Bash I have my PS1 as

PS1="\u@\h:\w\$(git branch 2>/dev/null | grep -e '\* ' | sed 's/^..\(.*\)/{\1}/') \$ "

Which will show my current git branch if I am in a git repo.

How do I set the PS1 in fish so it will show me my current git branch?


Solution

  • I think this is the equivalent

    function fish_prompt
        set -l git_branch (git branch 2>/dev/null | sed -n '/\* /s///p')
        echo -n (whoami)'@'(hostname)':'(prompt_pwd)'{'"$git_branch"'} $ '
    end