2

I'd like to see the current commit hash (just the first 8 or so characters) in my zsh prompt.

I have this so far: https://github.com/calebmeyer/cpm-zsh-theme/blob/master/cpm.zsh-theme#L3

git_commit_hash() {
  if [ -d .git ]; then
    git log -1 --pretty=oneline | cut -c -8
  fi
}

When I source the file, (via . ./cpm.zsh-theme), I see the commit hash for the current commit. However, it doesn't update when I change directories or make changes/commits. This also means that when I load up the theme on prompt start, there's no commit hash (and that never updates)

Here's a screenshot: my prompt!

How can I get zsh to re-evaluate this function on every new prompt?

Note: I'm using oh-my-zsh and antigen to manage my config. You can see my dotfiles here: https://github.com/calebmeyer/dotfiles

0

Try this:

PROMPT='other prompt stuff .. $(git_prompt_short_sha) more stuff '

Looking at what you linked though, the problem might just be that you're using double quotes instead of single quotes

  • Single quotes worked, and caused my commit_hash to be re-evaluated on every prompt. Exactly what I was looking for! You can see the results here – Caleb Apr 11 '16 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.