Hacker News new | ask | show | jobs
by an_ko 3944 days ago
I use a modified version of mislav's git prompt https://gist.github.com/mislav/1712320 which is pretty minimal but usually enough for me.

For when I have to wrangle lots of files at once (like during interactive rebase to clean up history before push) I have a git watch alias that shows a high-level overview of changes that refreshes with inotify:

  [alias]
      watch = "!clear;inotifywait --quiet -mr -e modify,move,create,delete --format \"%f %e\" @/.git . | \
  while read file; do \
      clear;\
      git status --short;\
      git --no-pager diff --shortstat;\
  done;"
I leave that running in a visible terminal window. It's more verbose than a prompt and reduces the need for constant git status sanity-checking. Maybe useful for someone.
5 comments

I like your `git watch` alias! That's very slick.

I like my git prompt to show me my branch name, colored with grey (no changes), red (unsaved changes), or green (staged changes), with the depth of the branch, e.g.:

    gknoy@host:~/dev/foo/[bar-feature:4]$ 

My prompt is based on: https://gist.github.com/tobiassjosten/828432

... but I've made slight modifications:

    # I sometimes have very long branch names.
    # I don't assume it's a hash:
    if [ ${#GIT_BRANCH} -gt 40 ]; then
        # GIT_BRANCH="(no branch)"
	GIT_BRANCH="${GIT_BRANCH:0:40}..."
    fi
and, at the end of `git_prompt`:

    branch_depth=`git rev-list HEAD --not --remotes|wc -l`
    echo "[$git_color$GIT_BRANCH$c_reset:${branch_depth}]"
I was missing a dot before /.git and can't edit the parent anymore… It should read

  [alias]
      watch = "!clear;inotifywait --quiet -mr -e modify,move,create,delete --format \"%f %e\" @./.git . | \
  while read file; do \
      clear;\
      git status --short;\
      git --no-pager diff --shortstat;\
  done;"
Sorry!
I'm going to steal this, thanks. I'll probably make it a script file instead of an alias, though.
Post the Gist when you're done, please?
How would this need to be changed to work on osx?
Just need to replace inotifywait with an FSEvents-based change watcher.
watchman (https://github.com/facebook/watchman) is cross platform.
It's less efficient, but you could just use a timed solution like watch:

   watch -n 2 'git status --short; git --no-pager diff --shortstat;'
This works on OSX:

  while :; do clear; git status --short; git --no-pager diff --shortstat; sleep 2; done
On my machine (archlinux, xterm) it flickers, as if there was a loop. Anybody sees the same ?
If you add an

  echo "$file"
inside the while loop, what do you see?

I deliberately set the .git directory to be ignored (using @) to avoid tons of repeating when the index.lock file is repeatedly recreated. Maybe that's what's going on here.

index.lock CREATE index.lock DELETE

alternating very fast.

Agh, it's my fault.

I must have fumbled a key after pasting, as there was a dot missing; @/.git should read @./.git.

I'll add a note to the ancestor comment if I still can. Thanks and sorry!