<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,7 +4,7 @@
 
 require 'socket'
 require 'tempfile'
-types ={
+$types ={
   &quot;0&quot;=&gt;&quot;TXT&quot;,
   &quot;1&quot;=&gt;&quot;DIR&quot;,
   &quot;2&quot;=&gt;&quot;CSO&quot;,
@@ -23,17 +23,21 @@ types ={
 pager=&quot;less&quot;
 pagermode=0
 
-opts=ARGV[0] ? ARGV[0].split('/') : [&quot;robsayers.com&quot;,&quot;1&quot;,&quot;/&quot;]
-host = opts.shift || 'robsayers.com'
-type = opts.shift 
-
-if !types.has_key?(type) then
-  opts.unshift(type)
-  puts &quot;No type given, assuming 1&quot;
-  type=&quot;1&quot;
+def parseurl(url)
+  opts=url.sub('gopher://','').split('/') # split the url by slashes
+  host=opts.shift # the first element will be our host
+  type=opts.shift # type is second
+  if !$types.has_key?(type) then # check to see if a type was provided
+    opts.unshift(type) # if not, then its part of the path, put it back
+    puts &quot;No type given, assuming 1&quot; # tell them the error of their ways
+    type=&quot;1&quot; # and assume its a directory
+  end
+  path = opts.first.nil? ? '/' :  opts.join('/') # if no path is provided, we go to the root
+  [host,type,path] # return it!
 end
+  
+host,type,path=parseurl(ARGV[0] || 'robsayers.com' ) 
 
-path = opts.join('/') || '/'
 
 history=[]
 input=&quot;&quot;
@@ -53,9 +57,14 @@ while input!=&quot;quit&quot; do
   rescue
     puts &quot;Error connecting to &quot;+host
   end
-  history &lt;&lt; [host,path,type]
+  history &lt;&lt; [host,path,type] # so we can go back later
   case type
   when &quot;0&quot;
+
+    # pagermode will write the data to a temp file, then pipe it through less
+    # if pager mode is not on, it will not save anything, I'm considering 
+    # forcing it anyhow for caching... good idea?
+
     if pagermode == 1 then
       fp=Tempfile.new('redgopher')  
       fp.puts t.read
@@ -74,7 +83,7 @@ while input!=&quot;quit&quot; do
       linedata = l.split(&quot;\t&quot;)
       linetype=l[0]
       desc=linedata[0][1,linedata[0].length-1]
-      if type=='i' || types[linetype].nil?
+      if type=='i' || $types[linetype].nil?
         if pagermode==1 then 
           fp.puts desc
         else
@@ -82,9 +91,9 @@ while input!=&quot;quit&quot; do
         end
       else
         if pagermode==1 then
-          fp.puts count.to_s+&quot;. [&quot;+types[linetype]+&quot;] &quot;+desc
+          fp.puts count.to_s+&quot;. [&quot;+$types[linetype]+&quot;] &quot;+desc
         else
-          puts count.to_s+&quot;. [&quot;+types[linetype]+&quot;] &quot;+desc
+          puts count.to_s+&quot;. [&quot;+$types[linetype]+&quot;] &quot;+desc
         end
         res[count]=[linedata[2],linedata[1],linetype]
         count+=1
@@ -92,7 +101,9 @@ while input!=&quot;quit&quot; do
     end
     fp.close if pagermode==1
     system pager +&quot; &quot;+fp.path if pagermode==1
-  else 
+  else # if its not a dir or text file, prompt to save
+    # i will eventually have handlers for at least html and telnet
+    # maybe even more
     if types.has_key?(type) then
       filename = path.split('/').last
       print &quot;Save File? (y/n)&quot;
@@ -120,8 +131,8 @@ while input!=&quot;quit&quot; do
       type=res[input.to_i][2]
     end
   elsif input == &quot;b&quot;
-    history.pop unless history.length==1
-    host,path,type = history.pop
+    history.pop unless history.length==1 # remove the last item unless there is only 1(the current url)
+    host,path,type = history.pop # remove the current url
   elsif input == &quot;r&quot;
     path=&quot;/&quot;
     type=&quot;1&quot;
@@ -137,9 +148,9 @@ while input!=&quot;quit&quot; do
   elsif input == &quot;&quot;
     # do nothing
   else
-    type=&quot;1&quot;
-    host=input
-    path=&quot;/&quot;
+    
+    host,type,path=parseurl(input)
+    
   end
 end
 </diff>
      <filename>redgopher.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>dbae57c3ad12d611ee0946a705c4183d71fd9e94</id>
    </parent>
  </parents>
  <author>
    <name>Rob Sayers</name>
    <email>rsayers@robsayers.com</email>
  </author>
  <url>http://github.com/rsayers/redgopher/commit/44b34a0951dc4b947005bee5f8a169e9af948483</url>
  <id>44b34a0951dc4b947005bee5f8a169e9af948483</id>
  <committed-date>2009-04-01T16:43:40-07:00</committed-date>
  <authored-date>2009-04-01T16:43:40-07:00</authored-date>
  <message>can now enter a full url from the command prompt</message>
  <tree>3ba9f937344f682b9d5e361689cdef04bf501705</tree>
  <committer>
    <name>Rob Sayers</name>
    <email>rsayers@robsayers.com</email>
  </committer>
</commit>
