jimeh / git-aware-prompt

Display current Git branch name in your terminal prompt when in a Git working directory.
Creative Commons Zero v1.0 Universal
2.15k stars 340 forks source link

Does this work with zsh? #71

Open cmacdonnacha opened 4 years ago

cmacdonnacha commented 4 years ago

Does this work with zsh?

danday74 commented 3 years ago

yup I would like to know the answer too

also see - https://stackoverflow.com/questions/65041568/iterm2-use-bash-as-well-as-zsh

I am happy to use zsh but asked this SO question so that if git-aware-prompt only works with bash then I need bash!

danday74 commented 3 years ago

works with bash for me - exact same setup does not work with zsh

emmahsax commented 3 years ago

I can affirm, I just tried switching to zsh, and git-aware-prompt does not work with zsh, but continues to work with bash beautifully.

However, here's a zsh solution (found from various articles and stuff over the internet):

# Load version control information, set git branch, and load colors
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats '(%b)'

# Mon Jan 01 13:26:31 ~/path/to/current_dir (git-branch)
# %
setopt PROMPT_SUBST
PROMPT='%B%F{cyan}%D{%a %b %d %H:%M:%S} %F{yellow}${PWD/#$HOME/~} %F{green}${vcs_info_msg_0_}'$'\n''%f%% %b'

I also color my prompt, so the date/time is cyan, the path is yellow, and the branch is green.

emmahsax commented 3 years ago

@danday74 and @cmacdonnacha I updated my comment above to provide a zsh solution that does the same thing as git-aware-prompt.

jimeh commented 3 years ago

I'm afraid git-aware-prompt is very specific to bash right now. For years I have wanted to do a complete rewrite that'll work on both bash and zsh, as I haven't personally used git-aware-prompt since 2011 when I switched to zsh.

And I would very much like to start using my own solution again rather than a third party one. Right now most of my spare time is going towards my emacs-builds project, but I've just bumped the bash+zsh rewrite up into second place on my todo list, so this time I'm hoping I'll actually get around to it 🤞

joeytwiddle commented 3 years ago

My fork supports zsh, and has a bunch of extra options.

I have also made a PR to add zsh support to this repo.