Show a side-by-side git diff on any commit in tig using Meld

Side-by-side diffs are more readable to me than in-line diffs. Long time ago, I started using Meld to display them when working with git. But I always needed to manually specify branch or commit names. This week I finally spent some time and found a way to invoke Meld directly from tig, so that I can see the diff side-by-side while browsing a commit history in tig (for example, when I want to review a proposed branch containing 10 new commits, and I want to inspect each of them individually). Here’s a short howto.

First, let’s configure Meld as your git difftool:

git config --global diff.tool meld

You can now see a diff between two branches/commits with:

git difftool -d branch1 branch2

That’s a lot of typing, though, so let’s create a handy alias:

git config --global alias.dt 'difftool -d'

And now you can use:

git dt branch1 branch2

And now, let’s integrate this into tig. Edit ~/.config/tig/config and add this snippet:

# use difftool to compare a commit in main/diff view with its parent
# https://github.com/jonas/tig/issues/219#issuecomment-406817763
bind main w !git difftool -d %(commit)^!
bind diff w !git difftool -d %(commit)^!

Notice I chose the “w” key as a shortcut key, because it’s unassigned by default. You can choose a different shortcut of course, see man tigrc.

Now anytime you want to see a side-by-side diff on any commit displayed in tig:

You simply press w and you’ll see the diff between the commit and its parent show up in Meld:

This improved my life a lot, perhaps it helped you as well 🙂 Cheers.

The beauty of Pdb

I never used Pdb much. I always thought that I had to run my whole script through the debugger, set some breakpoints through obscure commands and whatnot. But it is not the case. I can do simply this:

#!/usr/bin/env python
do_some_stuff()
import pdb
pdb.set_trace()
do_some_other_stuff()

Now you run your script as usual, and it stops at the pdb.set_trace() line and opens up a Pdb prompt. Then you can go line by line, explore and set variable contents and find out the source of your problem. Great! This approach is convenient and easy to use.

You need to know just a several basic commands to be able to do quite a lot in the Pdb shell. Read this 10-minute introduction, it’s worth it: Debugging in Python

Enjoy.

Flattr this

IPython GUI

Did you know that IPython has GUI? I didn’t. Then I’ve found ipython-gui package by accident. Wow, what is this?

This package contains the gui of ipython, which requires PyQt.

Nice, let’s try that out. I installed ipython-gui and… nothing. No new desktop launcher installed. No new executable installed. No new man page. No documentation of any kind. Nothing. Inspecting man ipython yielded same (no) results.

After dozens minutes spent Googling, I finally found the magic command:

$ ipython qtconsole

Hah, you are no match for me, ipython developers, I’ve found it in the end!

So once we know how to run it, what does it do? Well it is an improved IPython console. Main features I noticed in the first few minutes:

  • Syntax highlighting.
  • Tab completion hints disappear nicely and don’t “reset” your current line.
  • Methods docstrings are shown in the form of tooltips immediately after typing the opening parenthesis.
  • True multi-line editing support. You can finally invoke a multi-line command from history and easily change a single line. Yes!

 

Flattr this