Search code examples
gitdiffgit-config

How to pass a filename argument gitconfig diff textconv?


The documentation on textconv at https://git.wiki.kernel.org/index.php/Textconv has the succinct wording:

~/.gitconfig must indicate the command to execute for the the textconv driver:

[diff "<driver_name>"]
    textconv=<command>

I cannot find any documentation on how to format a command which requires the filename passed as a positional argument. For example, I'd like to use the following pdf formatter command, which requires a dash as last argument to write to stdout:

[diff "pdf"]
    textconv = pdftotext -layout "$1" -

For now I've had to write custom one-liner shell-scripts as a workaround, but they start to accumulate, and it becomes a bit annoying.

Is there a way to do without those scripts? The "$1" or xargs' '{}' convention for arguments don't seem to work.


Solution

  • As a workaround for gitconfig lacking parameter substitution functionality, you can wrap the command into a shell call, as in

    [diff "pdf"]
        textconv = sh -c 'pdftotext -layout -enc UTF-8 "$0" -'
    

    (found here: https://gist.github.com/t-yuki/9348e5d4aa4a75a6acf9)