Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have this alias:

alias hgd='hg diff|mate'

The problem is that for some reason the temporary file thus created will be a .txt, while I'd need it to have the diff syntax highlight.

If I manually change the highlight to diff, then every .txt I'll open in future will use the diff highlight too.

What can I do to fix that?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

TextMate can use either the file extension or the first line of a file to divine what filetype it is.

For my diff bundle (I think it's the original), this is:

firstLineMatch = '(?x)^
        (===\ modified\ file
        |==== \s* // .+ \s - \s .+ \s+ ====
        |Index:\ 
        |---\ [^%]
        |\*\*\*.*\d{4}\s*$
        |\d+(,\d+)* (a|d|c) \d+(,\d+)* $
        |diff\ --git\ 
        )
    ';

I don't have mercurial, but it appears as though its diff's first line may look something like diff -r 2278160e78d4 hello.c. As such, you can add another line to that big OR switch:

        ...
        |diff\ --git\ 
        |diff\ -r\ 
        )
    ';

Note that the final character in the line is a space.

As another alternative, it appears as though you may be able to define your alias as alias hgd='hg diff --git|mate' to use the same format as git, which is already recognized by TextMate.

share|improve this answer
add comment

I don´t have any mercurial project myself, but if you do this in svn (eg. with svn diff -r 100:099) it generates a .txt too, but it uses the diff highlighting - maybe there is an update to the diff bundle available in your installation?

If not, you can still re-write your alias to something like hg diff > /tmp/hg.diff && mate /tmp/hg.diff

share|improve this answer
add comment

Doing this with an alias won't work, but you can write a bash function that will handle this. Something like:

function hgd {
    T=`mktemp /tmp/hgdiff.XXXXXX.diff`
    hg diff > $T
    mate -w $T
    rm $T
}

in your .bash_profile will work. This acts closer to what you're trying to accomplish in that it leaves no trace of the temporary file on disk when you're done looking at it with TextMate.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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