#!/bin/bash

set -P
APP_DIR=${0%/*}
if [ "$APP_DIR" = "$0" ]; then
     APP_DIR=. ;
fi
APP_DIR=`cd "$APP_DIR";pwd`; export APP_DIR

if [ -n "$1" -a "$1" != "-" ]; then
    cd ${1%/*}
fi

if which gvim 2>/dev/null; then
    exec gvim "$@"
else
    file=$(basename ${1:-Untitled})
    xterm -T "VIM: $file" ${file:+-n $file} -name VIM -e vim "$@"
fi
