#!/bin/sh

# A quick hack to get wine to start the Windows application associated
# with the file type of the specified file arguments.
# This script can be used to easily open files in Windows applications
# from the commandline or a file manager.

# The idea is to start Wine from the root directory, and have all paths
# of the file arguments be relative to '/', to make sure that the first
# file argument to 'wine start' does not begin with a slash.
# This script should work with absolute as well as relative paths, and with
# paths containing spaces.

if [ $# -lt 1 ]; then
  echo "Usage: `basename $0` file..."
  exit 1
fi

# Save working dir and make it relative to '/'
d="`pwd`"
d="${d#/}"

# Prepend '/' to all paths as a placeholder
set "${@/#//}"
# Paths that were absolute now start with '//'. Remove this
set "${@#//}"
# Paths that were relative now start with '/'. Prepend the saved working dir
set "${@/#\//$d/}"

# Finally, start Wine
cd /
exec wine start "$@"
