#!/bin/bash

# ec2ssh
#
# @copyright Copyright (c) fruux GmbH. All rights reserved.
# @author Dominik Tobschall (http://fruux.com/)


# Changing the window title
setwindowtitle() {
    printf "\033k$1\033\\"
}

#
# Find script path
#
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
  DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

 #
 # Hand arguments to ec2dnshelper if we have any
 #
if [ "$#" -ge 1 ]; then
    eval $($DIR/ec2dnshelper $@)
    setwindowtitle "ec2:$ec2host"
else
    ec2args=""
fi

#
# run ssh
#
ssh $ec2args

# back to some default.. could be wrong I suppose, but I'm not fully sure how
# to capture the old name, and set that instead.
setwindowtitle bash
