#!/bin/sh

if [ -z $1 ]; then

  LASTHOST="$HOME/.ssh/lasthost"
  TEXT="SSH is a secure way to login to a remote computer.\n
You must have an user account on that computer.\n
Please select the hostname from the list,\n
or type it by yourself like this:\n 
[username@]hostname.example.net.\n
Enter username only if other than $USER"

  if [ -f $LASTHOST ]; then
     HOSTLIST=`cat $LASTHOST`
  fi

  for LINE in `awk '{ print $1 }' < $HOME/.ssh/known_hosts `
  do
    HOST=`echo $LINE | cut -d ',' -f 1`
    HOSTLIST="$HOSTLIST $HOST"
  done
  if [ -z "$HOSTLIST" ]; then
     HOSTLIST="localhost"
  fi

  mkdir -p ~/.ssh
  Xdialog --title "SSH" --editable --combobox "$TEXT" 16 50 $HOSTLIST 2> $LASTHOST

  [ ! $? = 0 ] && exit 1

  HOST=`cat $LASTHOST`
  if [ "$HOST" ]; then
    exec terminal -title "SSH-Terminal" -e $0 $HOST
  fi
  exit 0
fi

ssh $1
if [ ! $? = 0 ]; then
   echo "Error. press Enter to quit"
   read
fi
