1

I am trying to echo to the console in the event that a successful git checkout happened, but cannot get it to work.

function prompt_command {
   prev=`fc -ln -1`
   ecode=$?

   if [ ecode = 0 ]
   then
      if [ `echo $prev | grep -c "^git co -b"` -ge 0 ] || [ echo $prev | `grep -c "^git checkout -b"` -ge 0 ]
      then
        echo "SUCCESSFULLY CHECKED OUT!"
      fi
   fi
}

export PROMPT_COMMAND=prompt_command

Context: The eventual aim is to update the new git branch's description to indicate which branch it was checked out from. E.g. If I checkout "my_new_feature" from "dev", I want to automatically run: git config branch.my_new_feature.description "[FROM:dev]"

Then modify the prompt to include the parent branch.

2

1 Answer 1

1

[ ecode = 0 ] should be [[ "$ecode" -eq 0 ]]:

  • Double brackets
  • Use More Quotes™
  • Use a dollar sign in front of variables to expand them ([[ is a special case where you don't strictly need dollar signs or quotes in this case)
  • Use -eq for integer comparison

You must log in to answer this question.

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