Skip to content

Tig Integration With PowerShell (using Cygwin)

Luca Palonca edited this page May 23, 2022 · 3 revisions

Purpose

To allow Posh-Git users to use the very powerful Tig Git repository browser (it also has other functions such as blame tools etc...) from your PowerShell session so that you can use Posh-Git and Tig together from a PowerShell session.

Install Cygwin

First step is to install default Cygwin if you don't already have it. https://cygwin.com/install.html

Install Tig

Follow below Instructions to compile and install Tig. You will probably have to modify your Cygwin to get some additional packages to get it to compile but the instructions are quite clear as you progress. https://github.com/jonas/tig/blob/master/INSTALL.adoc

Write PowerShell script for your environment and put on default module import path

An example is below that will probably work on most machines using a standard Tig compile and install through Cygwin. I have placed it at ~\Documents\WindowsPowerShell\Modules\Tig\tig.psm1

function tig() {
    
    $arguments=""
    foreach($element in $args) {
        $arguments += " $element"
    }    

    if(-Not ($env:PATH.Contains("C:\cygwin64\bin"))) {
        echo 'cygwin not in path, appending environment variable'
        $env:PATH += ";C:\cygwin64\bin\";
    }
    iex -c 'C:\cygwin64\bin\bash.exe -c "source /home/ebrimah/.bashrc; /usr/local/bin/tig $arguments"';
}

Conclusion

The above steps will allow you to launch a bash cygwin shell from PowerShell command line using the tig command and use the Tig tool. Once you quit the tool you will be returned to your PowerShell session.