Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

fish

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?

like image 968
Alexandre Santos Avatar asked Jul 04 '14 23:07

Alexandre Santos


People also ask

How do I customize my fish shell prompt?

Prompt Tab The "prompt" tab displays the contents of the current fish shell prompt. It allows selection from 17 predefined prompts. To change the prompt, select one and press "Prompt Set!".

Where is fish shell config file?

If you want to organize your configuration, fish also reads commands in . fish files in ~/. config/fish/conf.

How do you switch to a fish shell?

Switching to fish? If you wish to use fish (or any other shell) as your default shell, you need to enter your new shell's executable /usr/local/bin/fish in two places: add /usr/local/bin/fish to /etc/shells. change your default shell with chsh -s to /usr/local/bin/fish.

How do you find a fish shell?

Modern shells save previous commands in a command history. You can view earlier commands by using the up and down arrows. Fish extends this concept by integrating the history search functionality. To search the history, simply type in the search string, and press the up arrow.


1 Answers

@glenn already got the answer, but I've found a simpler way of showing the git prompt on fish.

From the terminal, in fish, type fish_config. This will open a browser window. Select the second tab prompt and under there select Classic + Git`.

This will show the commands required to show Git on the terminal prompt. Copy them to your ~/.config/fish/config.fish or even simpler: click on "Use prompt".

How awesome is that?

like image 144
Alexandre Santos Avatar answered Oct 13 '22 14:10

Alexandre Santos