Saturday, July 4, 2015

All the little thing hacks - Cygwin + msysGit integration and ssh-pageant for Cygwin tools availability and Git SSH auth


Assuming of the following preconditions:
  • Microsoft Windows is installed on a PC
  • msysGit is installed with Microsoft Windows
  • Cygwin is installed with Microsoft Windows
  • User's $HOME is configured as to be uniform across the msysGit BASH and Cygwin BASH terminals
  • PuTTY's Pageant tool is installed and initialized in the user's desktop environment
  • The Cygwin ssh-pageant package is installed

...then the following SH snippet may be added to a users's ~/.bashrc file, to an effect:
  • That Git will then be able to use ssh-pageant when authenticating to remote Git repositories
  • That the user will furthermore be able to access the more of tools installed with Cygwin

Snippet follows
# n.b `uname -o` may not be available in MINGW32_NT-6.2
case $(uname -a) in
    ## Define a CYGHOME pathname in terminal-local pathname syntax

    MINGW*)
        
        ## e.g msysGit BASH terminal
        ##
        ## add Cygwin path, for convenience
        ##
        ## Notes:
        ##
        ## * The MINGW32_NT terminal provdies UNIX-like patnames for
        ##   Microsoft Windows drive volumes in a way divergent from
        ##   Cygwin's own volume=>pathname mapping.
        ##
        ## * If git is also installed with Cygwin, then it may result
        ##   in unexpected behaviors to add Cygwin to the PATH for
        ##   msyGit. Thus, this script will not modify $PATH if Git is
        ##   known to be installed under Cygwin
        ##
        ## * If Cygwin is not known to be installed, CYGHOME will not
        ##   be defined
        
        if [ -d "/C/cygwin64" ]
          then CYGHOME="/C/cygwin64"
        elif [ -d "/C/cygwin" ]
          then CYGHOME="/C/cygwin"
        else unset CYGHOME
        fi
        
        if [ -n "$CYGHOME" -a ! -x "$CYGHOME/bin/git.exe" ]; then
            PATH="${PATH+$PATH:}$CYGHOME/bin"
            export CYGHOME PATH
        fi
             
        ;;
    
    CYGWIN*)
        export CYGHOME="/"
        ;;
esac

eval $(ssh-pageant)


The previous SH snippet is provided by its author, Sean Champ, 4 July 2015, under a public domain #YMMV license.


No comments:

Post a Comment