Hemanth.HM

A Computer Polyglot, CLI + WEB ♥'r.

Auto Notify Git Pull

| Comments

So, here the code I came up with [First cut] :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function cd() {
  async() {
    {
      $2 $($1)
    }&
  }

  notify_callback() {
    [[ $1 > 0 ]] && echo "You have new stuff to pull!"
  }

  # If it's a git repo, check if we need to pull.
  if git rev-parse --is-inside-work-tree &>/dev/null; then
    async "git rev-list HEAD...origin/master --count" notify_callback
  fi
 
  builtin cd "$@"
}

Place this in your .bashrc to override the cd command, to check if you cd to a git repo and then check and notify you if you need to pull stuff.

Happy Hacking! :-)

Update 0:

Better approach would be to use (( $(git rev-list HEAD..@{u} --count) > 0 )) && echo "There are new things to merge"

Comments