Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing end to balance this if statement

i try to add this lines to my .bash-profile

if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ];then
 source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi

but I get this error

Missing end to balance this if statement
.bash_profile (line 2): if [ -f "$(brew --prefix)/opt/bash-git-       prompt/share/gitprompt.sh" ]; then
                    ^
from sourcing file .bash_profile
called on standard input

Dose anyone have an idea why? I have the code from here https://github.com/magicmonty/bash-git-prompt

like image 370
Arthur Avatar asked Sep 14 '16 18:09

Arthur


Video Answer


2 Answers

This error message:

Missing end to balance this if statement
.bash_profile (line 2): if [ -f "$(brew --prefix)/opt/bash-git-       prompt/share/gitprompt.sh" ]; then
                    ^
from sourcing file .bash_profile
called on standard input

is generated by the fish shell.

The .bash_profile file is intended only to be executed (sourced) by the bash shell. fish is a different shell, with different syntax; it's not compatible with bash.

If you're using fish as your interactive shell, and you want some commands to be executed automatically when you start a new shell, you'll need to translate the bash-specific commands to fish syntax and add them to your fish startup file. (Not a lot of people use fish, so providers of software packages aren't likely to provide startup commands in fish syntax -- but this package apparently does; see chepner's answer.)

like image 70
Keith Thompson Avatar answered Oct 14 '22 05:10

Keith Thompson


Although the linked repository contains a script for fish, the README does not provide any directions for how to use that script. Not having used fish in several years, I think what you want to do is add

if status --is-login
  source (brew --prefix)"/opt/bash-git-prompt/share/gitprompt.fish"
end

to ~/.config/fish/config.fish instead. The if status command prevents the file from being unnecessarily sourced if you aren't starting an interactive shell.

like image 11
chepner Avatar answered Oct 14 '22 07:10

chepner