<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 #!/usr/bin/env ruby
 # Author: Joseph Pecoraro
 # Date: Saturday December 13, 2008
+# Updated: Friday June 26, 2009
 # Description: When I'm using ExpanDrive and I'm
 # remotely logged into a server, I can use this
 # script to &quot;open filename&quot; and it will open using
@@ -15,21 +16,10 @@ require 'optparse'
 $options = { :url =&gt; false }
 OptionParser.new do |opts|
 	opts.banner = 'usage: expanurl [option] [files]'
-	opts.on(&quot;-u&quot;, &quot;--url&quot;, &quot;Print the URL that would have been used.&quot;) do |u|
-		$options[:url] = u
-	end
-	opts.on_tail(&quot;-h&quot;, &quot;--help&quot;, &quot;Show this message&quot;) do
-		puts opts
-		exit
-	end
+	opts.on(&quot;-u&quot;, &quot;--url&quot;, &quot;Print the URL that would have been used.&quot;) { |u| $options[:url] = u }
+	opts.on_tail(&quot;-h&quot;, &quot;--help&quot;, &quot;Show this message&quot;) { puts opts }
 end.parse!
 
-# Exit with a msg
-def err(msg)
-	puts msg
-	exit 1
-end
-
 # Properly open/print a url
 def handle_url(url)
 	if $options[:url]
@@ -79,69 +69,74 @@ end
 
 
 # Local Variables
+PWD = Dir.pwd
 mapping = UrlMap.new
 url_prefix = nil
 server = nil
 volume = nil
 
-# Check the if the current directory is an
-# ExpanDrive Volume and a public_html folder
-pwd = `pwd`
-match = pwd.match(/^\/Volumes\/([^\/]+)/)
-if match.nil?
-	err(&quot;Not inside an ExpanDrive Volume&quot;)
-elsif !pwd.match(/\/public_html\/?/)
-	err(&quot;Not inside a public_html directory.&quot;)
-else
-	volume = match[1]
-	defaults = `defaults read com.magnetk.ExpanDrive Drives`
-	defaults.gsub!(/\n/, '')
-	props = defaults.match(/\{[^\}]+driveName\s+=\s+#{volume}[^\}]+server\s+=\s+&quot;([^&quot;]+)&quot;[^\}]+\}/)
-	if props
-		server = props[1]
-	else
-		err(&quot;This Volume (#{volume}) is not an ExpanDrive Volume&quot;)
-	end
-end
+# Process Each File, Assume pwd if No File Given
+files = ARGV
+files &lt;&lt; PWD if ARGV.empty?
+files.each do |filename|
+  
+  # Expand the filename
+  filename = File.expand_path(filename)
+  
+  # Check the if the current directory is an
+  # ExpanDrive Volume and a public_html folder
+  match = filename.match(/^\/Volumes\/([^\/]+)/)
+  if match.nil?
+  	puts &quot;'#{filename}' is not inside an ExpanDrive Volume&quot;
+  	next
+  elsif !filename.match(/\/public_html\/?/)
+  	puts &quot;'#{filename}' is not inside a public_html directory.&quot;
+  	next
+  else
+  	volume = match[1]
+  	defaults = `defaults read com.magnetk.ExpanDrive Drives`
+  	defaults.gsub!(/\n/, '')
+  	props = defaults.match(/\{[^\}]+driveName\s+=\s+#{volume}[^\}]+server\s+=\s+&quot;([^&quot;]+)&quot;[^\}]+\}/)
+  	if props
+  		server = props[1]
+  	else
+  		puts &quot;This Volume (#{volume}) is not an ExpanDrive Volume&quot;
+  		next
+  	end
+  end
 
-# Check if a mapping exists
-# Otherwise create and store one
-if mapping.is_mapping?(server)
-	url_prefix = mapping.get_mapping(server)
-else
-	
-	# Prompt
-	puts
-	puts &quot;This is the first time you've used expanurl for #{volume}&quot;
-	puts &quot;Please Provide us with a mapping for #{server}&quot;
-	puts &quot;Mappings are stored in #{mapping.path}&quot;
-	puts &quot;Example: http://bogojoker.com/&quot;
-	print &quot;&gt;&gt; &quot;
-	
-	# Store user input and proceed
-	url_prefix = gets.chomp
-	url_prefix += '/' unless url_prefix.match(/\/$/)
-	mapping.add_mapping(server, url_prefix)
-	
-	# Terminal Output
-	puts
-	puts &quot;Server: #{server}&quot;
-	puts &quot;Maps to: #{url_prefix}&quot;
-	puts
+  # Check if a mapping exists
+  # Otherwise create and store one
+  if mapping.is_mapping?(server)
+  	url_prefix = mapping.get_mapping(server)
+  else
 
-end
+  	# Prompt
+  	puts
+  	puts &quot;This is the first time you've used expanurl for #{volume}&quot;
+  	puts &quot;Please Provide us with a mapping for #{server}&quot;
+  	puts &quot;Mappings are stored in #{mapping.path}&quot;
+  	puts &quot;Example: http://bogojoker.com/&quot;
+  	print &quot;&gt;&gt; &quot;
 
-# Build the URL
-subpath = pwd.match(/public_html\/?(.*)/)[1]
-subpath += '/' unless subpath.length.zero? || subpath.match(/\/$/)
-url_prefix += subpath
+  	# Store user input and proceed
+  	url_prefix = gets.chomp
+  	url_prefix += '/' unless url_prefix.match(/\/$/)
+  	mapping.add_mapping(server, url_prefix)
 
-# If No Files, open the directory
-# Otherwise,   open each provided file
-if ARGV.size == 0
-	handle_url( url_prefix )
-else
-	ARGV.each do |filename|
-		handle_url( &quot;#{url_prefix}#{URI.escape(filename)}&quot; )
-	end
+  	# Display Result
+  	puts
+  	puts &quot;Server: #{server}&quot;
+  	puts &quot;Maps to: #{url_prefix}&quot;
+  	puts
+
+  end
+  
+  # Build the URL subpath
+  subpath = filename.match(/public_html\/?(.*)/)[1]
+  subpath += '/' if !subpath.empty? &amp;&amp; File.directory?(filename) &amp;&amp; subpath !~ /^\/$/
+  
+  # Open the file/directory
+  handle_url( url_prefix + subpath )
+  
 end</diff>
      <filename>expanurl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>56c41b06f9c9d2a80525cf9a79207cf1382ffc05</id>
    </parent>
  </parents>
  <author>
    <name>Joseph Pecoraro</name>
    <email>joepeck02@gmail.com</email>
  </author>
  <url>http://github.com/JosephPecoraro/scripts/commit/10364cfc7dda6b91295160dd15b36a6b4e85fa0a</url>
  <id>10364cfc7dda6b91295160dd15b36a6b4e85fa0a</id>
  <committed-date>2009-06-25T21:18:31-07:00</committed-date>
  <authored-date>2009-06-25T21:18:31-07:00</authored-date>
  <message>Expanurl now evaluates the path of its arguments so you can call it from anywhere</message>
  <tree>cc1f003408ad4dbb46f8db14d4a5809941bbf288</tree>
  <committer>
    <name>Joseph Pecoraro</name>
    <email>joepeck02@gmail.com</email>
  </committer>
</commit>
