Wie kann ich git-completion.bash unter Mac OS X zum Laufen bringen?

57340
n179911

Ich habe http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-ohnegit-completion.bash zu meiner hinzugefügt/opt/local/etc/bash_completion.d/git-completion

und ich PS1='\h:\W$(__git_ps1 "(%s)") \u\$ 'füge mein .bashrc_profile ein

Aber jetzt bekomme ich das -bash: __git_ps1: command not foundalles was ich tue cd.

Können Sie mir bitte sagen, was ich vermisse?

88
Siehe auch: https://trac.macports.org/wiki/howto/bash-completion Ioannis Filippidis vor 6 Jahren 0

14 Antworten auf die Frage

65
Lara Dougan

Ich habe git mit MacPorts in meiner neuen Snow Leopard-Installation installiert. Nachdem MacPorts aus dem .dmg-Image installiert wurde, sind dies die Befehle in Terminal.app:

sudo port selfupdate sudo port install git-core +bash_completion 

Wenn Sie auch Unterstützung für das Abrufen von SVN-Repositorys und -Dokumenten benötigen, verwenden Sie diese anstelle der zweiten Zeile:

sudo port install git-core +bash_completion +doc +svn 

Fügen Sie dann zu Ihrem ~ / .profile oder ~ / .bash_profile Folgendes hinzu:

# MacPorts Beenden der Bash-Shellbefehle if [-f / opt / local / etc / bash_completion]; dann . / opt / local / etc / bash_completion fi

oder für MacPorts ab Version 2.1.2 auf Mountain Lion:

# MacPorts Beenden der Bash-Shellbefehle if [-f /opt/local/etc/profile.d/bash_completion.sh]; dann . /opt/local/etc/profile.d/bash_completion.sh fi

oder für MacPorts mit neueren Versionen von git:

if [-f /opt/local/share/git-core/git-prompt.sh]; dann . /opt/local/share/git-core/git-prompt.sh fi

Hinweis: Für bash_completion.sh ist bash 4.1 oder höher erforderlich. Wenn die Fertigstellung nicht funktioniert, überprüfen Sie echo $BASH_VERSION, ob dies der Fall ist . Wenn dies der Fall ist, geben Sie MacPorts bash ein, indem Sie den Befehl eingeben bash.

Ich habe gerade eingefügt und ich bekomme immer noch den Fehler, den das OP hat. = \. Wie kannst du sagen, was enthalten ist? Ich glaube nicht, dass bash_completion verwendet wird NullVoxPopuli vor 11 Jahren 0
Beachten Sie, dass sich die Eingabeaufforderung bei neueren Versionen von git / macport / bash-completion in einer anderen Datei befindet. Siehe: http://trac.macports.org/ticket/36334 `if [-f /opt/local/share/git-core/git-prompt.sh]; dann . /opt/local/share/git-core/git-prompt.sh fi` Yehosef vor 11 Jahren 0
Da `/ opt / local / etc / profile.d / bash_completion.sh` $ BASH_VERSION` 4.1 oder besser benötigt, musste ich unter Mac OS X 10.8.3 mit MacPorts 2.1.3 Folgendes tun: Wechseln Sie das Mac OS X Login-Shell von der Standardeinstellung `/ bin / bash` (3.2.48 (1) -release) nach MacPorts` / opt / local / bin / bash` (4.2.42 (2) -release) wie hier beschrieben: stackoverflow .com / a / 791244/287984. Grundsätzlich `` if [`grep / opt / local / bin / bash / etc / shells`]; dann echo / opt / local / bin / bash | chsh -s / opt / local / bin / bash; sonst echo / opt / local / bin / bash | Sudo tee -a / etc / shells; chsh -s / opt / local / bin / bash; fi`` Uwe Günther vor 11 Jahren 3
Arbeitete super für mich. Ich musste `/ bin / bash` in Terminal.app durch` / opt / local / bin / bash` von macports ersetzen. Alle hier vorgeschlagenen `.bash_profile`-Änderungen. bgs vor 10 Jahren 0
Um zu Bash 4.1 oder höher zu wechseln, folgen Sie den Anweisungen hier: http://apple.stackexchange.com/questions/70132/set-default-shell-to-macports-bash-in-mac-os-x-10- 6-8 ThomasW vor 10 Jahren 1
Der neueste OSX-Pfad lautet "/ opt / local / share / git / contrib / completion / git-prompt.sh" als Antwort hier [link] (http://stackoverflow.com/questions/12870928/mac-bash-git- ps1-command-nicht gefunden) bgs vor 9 Jahren 0
54
grundprinzip

Wenn Sie git mit Homebrew installiert haben, passen Sie den MacPorts-Hinweis ein wenig an und fügen Sie dies Ihrem .bash_profileund hinzu.bashrc

if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then . `brew --prefix`/etc/bash_completion.d/git-completion.bash fi 

Der beste Weg, um zu überprüfen, ob Sie git korrekt mit Homebrew installiert haben, ist die Ausführung

brew info git 

und überprüfen Sie die Ausgabe für das Installationsverzeichnis der Fertigstellung von git bash

Die neueste Version von Git (1.7.12) erfordert Folgendes, um die Eingabeaufforderung zu aktivieren.

if [ -f `brew --prefix`/etc/bash_completion.d/git-prompt.sh ]; then . `brew --prefix`/etc/bash_completion.d/git-prompt.sh fi 
Weitere Informationen zu `` __git_ps1`` finden Sie unter http://superuser.com/a/477749/90231 Antwort in diesem Stapel. RichVel vor 10 Jahren 0
26
iansheridan

All you need to do is place the git-completion.bash file in your user home bin directory and place the following in you .profile or .bash_profile file:

export PATH="$HOME/bin:$PATH" source ~/bin/git-completion.bash PS1='[\u@\h \w$(__git_ps1 " (%s)")]\$ ' 

What this does is make sure that your local bin is in the PATH and the source command gets things going. Then of course the PS1 change puts the currently checked out branch in the prompt.

So, no MacPort install to then install a the "completion" version of GIT (especially irritating if you already have it installed).

https://github.com/git/git/raw/master/contrib/completion/git-completion.bash Nickolay vor 13 Jahren 2
Wenn Sie sich fragen, wie Sie das PS1-Ding mit den Farben in Ihrer Eingabeaufforderung kombinieren können, lesen Sie die Informationen unter http://stackoverflow.com/questions/816790/append-gits-branch-name-to-command-prompt Nickolay vor 13 Jahren 1
Genauer gesagt, git-completion.bash muss sich nur irgendwo in Ihrem "$ PATH" befinden. Ich beschloss, meine in `/ usr / local / bin /` zu installieren, damit ich meinen vorhandenen `$ PATH` nicht ändern musste. metavida vor 12 Jahren 1
13
Andy

Während die aktuelle Antwort für ältere MacPorts korrekt ist, gibt es ein neues Problem mit den aktuellsten MacPorts, die zu demselben Fehler führen.

Das aktuelle Bash-Completion- Paket (2.0 r1) erfordert mindestens eine Bash 4.1, um ordnungsgemäß zu funktionieren. Wie ein übliches OS X Terminal verwendet /bin/bash, erhält es nur eine 3.x. Sie müssen Ihre Terminaleinstellungen ändern, um sie /opt/local/bin/bash -lwie in der MacPorts-Dokumentation hier beschrieben zu verwenden: http://trac.macports.org/wiki/howto/bash-completion

Dies ist die richtigste Antwort, da ich das Problem erst nach der Aktualisierung von Macports hatte. Der einzige Nachteil bei der Verwendung der macports-bash von terminal ist, dass ich jetzt vor dem Beenden laufender Prozesse gewarnt werde, wenn ich versuche, das Terminalfenster zu schließen. Haben Sie dieses Problem getroffen? vitch vor 11 Jahren 0
6
jtimberman

Sie müssen die Befehlsbeendigungsfunktionen beziehen. Fügen Sie Ihrem .bashrc_profile vor der PS1 hinzu:

. /opt/local/etc/bash_completion.d/git-completion 
git-completion.bash finden Sie hier: https://raw.github.com/git/git/master/contrib/completion/git-completion.bash TJ Biddle vor 10 Jahren 0
5
studgeek

Annoyingly this has been broken yet again. This time its the git folks with version 1.7.12-1. To allow people to have just the prompt functionality without the completion functionality (which can slows things down), they refactored the prompt functionality out of bash_completion/git and into its own file git-prompt.sh.

So adding bash_completion as described by @Lara will only get you completion (hitting tab completes tag/branch names).

To get the __git_ps1 so you can use it in your PS1 prompt you also need to add the following to your ~/.profile.

. /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh

Some background is here - https://bbs.archlinux.org/viewtopic.php?pid=1163632#p1163632

Die betreffende Datei: https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh papercowboy vor 11 Jahren 0
3
derek73

Oder mit Homebrew

brew install bash-completion git-extras 
Danke vielmals. Es sollte jedoch "brew install bash-completion git-extras" sein (Bindestrich statt Unterstrich). simonair vor 11 Jahren 2
2
John Mellor

Zu einer ähnlichen Frage eine Lösung gefunden :

Der git-osx-Installer kommt mit git-completion.bashund installiert es /usr/local/git/contrib/completion/. Einfach die Datei von Dir beziehen um .bash_profilezu bekommen __git_ps1.

2
haysclark

Für Mountain Lion und Mac-Ports musste ich die folgenden Zeilen in meinem .bash_profile verwenden, um sowohl __git_ps1 als auch Abschlüsse normal auszuführen:

# Bash shell command completion if [ -f /opt/local/share/doc/git-core/contrib/completion/git-completion.bash ]; then . /opt/local/share/doc/git-core/contrib/completion/git-completion.bash fi  if [ -f /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh ]; then . /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh fi 
1
ecloud

I use brew, so a master bash_completion script which runs all the ones in bash_completion.d seems not to be provided. The solutions which propose just running a single script to add git completions aren't extensible, because different packages will add different completion scripts, and you probably want to run them all. Therefore I added this (adapted from Arch Linux) to the end of /etc/bashrc:

# source compat completion directory definitions BASH_COMPLETION_COMPAT_DIR=/usr/local/etc/bash_completion.d if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \ -x $BASH_COMPLETION_COMPAT_DIR ]]; then for i in $(LC_ALL=C command ls "$BASH_COMPLETION_COMPAT_DIR"); do i=$BASH_COMPLETION_COMPAT_DIR/$i [[ -f $i && -r $i ]] && . "$i" done fi