#!/bin/bash

if [[ -e /bin/cygwin1.dll ]]; then
  alias ip="ipconfig | grep -E 'IP(v4)? Address' | sed -e 's/.*: //'"

  # o: "open" files as if double-clicked in Windows explorer
  function o
  {
    while [[ "$1" != "" ]]
    do
      if [[ -e "$1" ]]; then
        dn=$(dirname "$1")
        bn=$(basename "$1")
        (cd "$dn"; HOME='' cygstart "$bn")
      else
        HOME='' cygstart "$1"
      fi
      shift
    done
  }

  function winpython
  {
    local winpython=/c/Python27/python.exe
    if [[ "$1" == "" ]]; then
      ${winpython} -i
    else
      ${winpython} "$@"
    fi
  }

  winpath="$(echo $PATH | sed -e 's/:/\n/g' | grep cygdrive | tr '\n' ':' | sed -e 's/:*$//')"

  export SSH_AUTH_SOCK=/tmp/.ssh_socket

  function ssh_agent_start
  {
    # cygwin ssh-agent support, from
    # http://www.webweavertech.com/ovidiu/weblog/archives/000326.html

    ssh-add -l >/dev/null 2>&1

    if [ $? = 2 ]; then
      # exit status 2 means we couldn't connect to ssh-agent,
      # so let's start one now
      rm -f $SSH_AUTH_SOCK
      ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
      . /tmp/.ssh-script
      echo $SSH_AGENT_PID >/tmp/.ssh-agent-pid
      ssh-add ~/.ssh/JoshHoltropGentex
    fi
  }

  function ssh_agent_stop
  {
    pid=$(cat /tmp/.ssh-agent-pid)
    kill $pid
  }
fi
