5

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

1 Answer 1

5

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

1
  • 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
    Commented Apr 11, 2016 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .