1

When using git-grep, the output isn't sorted alphabetically which makes navigating the results more tedious then it should be.

Is there a way to sort the output?

I checked git-grep and it seems there are no options to do this from within git itself.

0

Posting an answer to my own question, it's a works albeit a little hacky.

This simply pipes git-grep to sort.

Create an executable shell script wrapper for git: ~/emacs.d/bin/git_sorted

#!/bin/bash
exec git ${1+"$@"} | sort -V

And in your emacs.d/init.el:

(setq
  counsel-git-grep-cmd-default
  "~/.emacs.d/bin/git_sorted --no-pager grep --full-name -n --no-color -e %S")

sort -V happens to sort line numbers correctly (-n, -h... don't).

Note, it would be nice if there was a way to only sort the file-list which git-grep uses, instead of having to sort the entire output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.