Skip to content

Instantly share code, notes, and snippets.

@aryelgois
Last active March 12, 2018 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aryelgois/c413ca5bf7bb9341c3c9181d492217d6 to your computer and use it in GitHub Desktop.
Save aryelgois/c413ca5bf7bb9341c3c9181d492217d6 to your computer and use it in GitHub Desktop.
Fix git colors for watch(1)
#!/usr/bin/env bash
# Fix git colors, userful for watch(1)
#
# @usage watch -c 'git colored <git command>'
# @see https://askubuntu.com/questions/967503 for an example of the problem and explanation
# run git command and replace all foreground colors to include '0'
exec git -c color.ui=always "$@" | sed -r $'s/\033\[([[:digit:]][[:digit:]])m/\033\[0;\\1m/g; s/\033\[m/\033\[0m/g'
@aryelgois
Copy link
Author

aryelgois commented Jan 17, 2018

Install

  1. git clone
  2. cp git-colored.sh ~/bin/git-colored

or you can symlink, if you like to keep repositories around.

@aryelgois
Copy link
Author

aryelgois commented Jan 17, 2018

My favorite usage:

watch -c 'git colored log -1; echo; git colored log --all --date-order --decorate --graph --oneline'

I aliased this in ~/.gitconfig:

[alias]
  watch = !watch -c 'git colored log -1 && echo && git colored log --all --date-order --decorate --graph --oneline'

note the && replacing ;

Simply keep a terminal running git watch inside your repository

the next step is making watch(1) scrollable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment