3

I just hacked my core.pager to show me more usefull log and diff:

[core]
; diff-so-fancy:
;   Seperate files in diff view
; LESS_TERMCAP ... +0 -p ...:
;   Highlight merge commits and file beginnings in diff view (but do not
;   jump because of `+0`), press `n` to jump to the next occurence
; -S:
;   Do not break long lines (useful for log --graph with branches)
pager = "diff-so-fancy | LESS_TERMCAP_so=$'\\E[1;37m' less --tabs=4 -RFX +0 -p 'Merge (branch|pull request) .*|^(added|deleted|modified): '"

screenshot

It's quite cool, but I don't like some behaviour of less. How can I prevent

  • Pattern not found message (for example when running git diff on a clean repo)?
  • redraw of the full screen (git log --oneline -5)?
  • the need of pressing q even on half screen messages (because of -S)?

whitespace bellow log

Note that if you want to use it without diff-so-fancy, then change ^(added|deleted|modified) to ^diff --git.

A SIMPLIFIED SOLUTION

pager = "diff-so-fancy | GREP_COLOR='1;37' grep --color=always -E 'Merge (branch|pull request).*|$' | less --tabs=4 -RFX"

It will only highlight merge commits, does nothing more.

bimlas
  • 2,359
  • 1
  • 21
  • 29
  • Those are all questions about `less` itself, rather than about Git. I'm not sure there's an appropriate tag here, or for that matter if that's even really an SO question in the first place, but: to avoid the "not found", don't search; to make less behave nicer on half-page, add `-F` to your options. You already have `-F` so I'm not sure why that's not working. – torek May 31 '17 at 13:16
  • @torek: I know that this topic is related to`less`, should I ask on https://unix.stackexchange.com? The half-page issue is caused by `-p` and `+0`. – bimlas Jun 01 '17 at 05:43
  • Unix.SE might be good. I don't hang out there nearly as much though. – torek Jun 01 '17 at 14:33
  • I just changed the way to highlight merge commits - see the updated question. – bimlas Jun 01 '17 at 20:36

1 Answers1

2

Pattern not found message (for example when running git diff on a clean repo)?

I hacked a solution that inspects the output of diff-so-fancy for matches of commit <SHA>, added:, removed:, etc. and only uses less --pattern when such matches were found.

https://github.com/agross/dotfiles/commit/8dc82ef2374172b89603f879742900a8499d8372

Alexander Groß
  • 10,200
  • 1
  • 30
  • 33