<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,20 +1,43 @@
+&quot; http://github.com/solars/github-vim/
+&quot; sol@textmode.at
+
 if exists(&quot;loaded_github&quot;) || &amp;cp 
   finish 
 endif
 
+
+&quot; --- main functions --- &quot;
+
 function! s:Open() range
-  let $GIT_LINE_START=a:firstline
-  let $GIT_LINE_END=a:lastline
-  let $GIT_FILEPATH=expand(&quot;%:p&quot;)
-  rubyf $HOME/bin/github_open.rb
+  if empty(s:RepositoryRoot()) || empty(s:Remote())
+    echo &quot;File not in repository or no remote found!&quot;
+  else
+    let url = s:ReposUrl().'/'.s:RelPath().'#L'.a:firstline.'-'.a:lastline
+    call system(&quot;openUrl '&quot;.url.&quot;'&quot;)
+  end
 endfunction
 
-function s:Comment()
-  let $GIT_CURRENT_LINE = getline('.')
-  let $GIT_FILEPATH = expand(&quot;%:p&quot;)
-  rubyf $HOME/bin/github_comment.rb
+function! s:Comment()
+  if empty(s:RepositoryRoot()) || empty(s:Remote())
+    echo &quot;File not in repository or no remote found!&quot;
+  else
+    let url = s:ReposUrl().'/'.s:RelPath().'#L'.a:firstline.'-'.a:lastline
+    let line = line('.')
+    let output = s:CdExec(s:RepositoryRoot(),'git blame -l -s -L '.line.','.line.' '.s:RelPath())
+    if empty(output)
+      echo &quot;No commit found&quot;
+      return
+    end
+    let commit = split(output)[0]
+    let index=s:CommitIndex(commit)
+    let url = s:ProjectUrl().'/commit/'.commit.'/'.s:RelPath().'#diff-'.index
+    call system(&quot;openUrl '&quot;.url.&quot;'&quot;)
+  endif
 endfunction
 
+
+&quot; --- key mappings --- &quot;
+
 if !hasmapto('&lt;Plug&gt;GithubComment', 'n')
   nmap &lt;unique&gt;ghc &lt;Plug&gt;GithubComment
 endif
@@ -27,6 +50,104 @@ endif
 vnoremap &lt;unique&gt; &lt;script&gt; &lt;Plug&gt;GithubOpen &lt;SID&gt;Open
 vnoremap &lt;silent&gt; &lt;SID&gt;Open :call &lt;SID&gt;Open()&lt;CR&gt;
 
-&quot; override mappings with:
-&quot; map &lt;F5&gt; &lt;Plug&gt;GithubOpen
-&quot; map &lt;F6&gt; &lt;Plug&gt;GithubComment
+
+&quot; --- helpers --- &quot;
+
+&quot; repository root path of current file
+function! s:RepositoryRoot() &quot;+error checks
+  if !exists('b:repos_root')
+    let dir = expand(&quot;%:p:h&quot;)
+    let rel_path = s:CdExec(dir,'git-rev-parse --show-cdup')
+    if !empty(matchstr(rel_path,'fatal'))
+      return
+    end
+    let rel_path = substitute(rel_path, &quot;\n&quot;,'','g')
+    let b:repos_root = simplify(dir.'/'.rel_path)
+  endif
+  return b:repos_root
+endfunction
+
+&quot; current branch name
+function! s:CurrentBranch()
+  if !exists('b:branch')
+    let branches = s:CdExec(expand(&quot;%:p:h&quot;),&quot;git branch&quot;)
+    if empty(branches)
+      return
+    endif
+    let b:branch = matchstr(branches, '\* \zs.\{-}\ze\n.*')
+  endif
+  return b:branch
+endfunction
+
+&quot; relative path of the current file to the repository root 
+function! s:RelPath()
+  if !exists('b:rel_path')
+    let root = escape(s:RepositoryRoot(),'./')
+    let file = expand('%:p')
+    let b:rel_path = strpart(file,matchend(file, root))
+  endif
+  return b:rel_path
+endfunction
+
+&quot; finds the github remote repository identifier
+&quot; precedence: github &gt; origin &gt; other
+function! s:Remote()
+  if !exists('b:remote')
+    let remotes = split(s:CdExec(expand(&quot;%:p:h&quot;),'git remote -v'),&quot;\n&quot;)
+    let github_remotes = filter(remotes, 'v:val =~ &quot;github\.com&quot;')
+    if empty(github_remotes)
+      return
+    endif
+    let dict={}
+    for line in github_remotes
+      let [name,url]=split(line)
+      let dict[name]=url
+    endfor
+    let fallback = split(github_remotes[0])[1]
+    if has_key(dict, 'github')
+      let b:remote = dict['github']
+    elseif has_key(dict,'origin')
+      let b:remote = dict['origin']
+    else
+      let b:remote = fallback
+    end
+  endif
+  return b:remote
+endfunction
+
+&quot; the github project url
+function! s:ProjectUrl()
+  if !exists('b:project_url')
+    let remote_url = s:Remote()
+    let user = matchstr(remote_url,'.*github\.com[:/]\zs[^/]\+\ze\/.*')
+    let project = matchstr(remote_url,'.*github\.com[:/][^/]\+\/\zs[^.]\+\ze\.git')
+    let b:project_url = 'http://github.com/'.user.'/'.project
+  endif
+  return b:project_url
+endfunction
+
+&quot; the github repository url
+function! s:ReposUrl()
+  if !exists('b:repos_url')
+    let b:repos_url = s:ProjectUrl().'/tree/'.s:CurrentBranch()
+  endif
+  return b:repos_url
+endfunction
+
+&quot; index of a filename in the diff output
+function! s:CommitIndex(commit)
+  if !exists('b:index')
+    let output = s:CdExec(s:RepositoryRoot(),'git diff --name-only '.a:commit.'^..'.a:commit)
+    let b:index = index(split(output,'\n'),s:RelPath())
+  endif
+  return b:index
+endfunction
+
+&quot; executes cmd in the given dir
+function! s:CdExec(dir,cmd)
+  let cur_dir=getcwd()
+  exe 'lcd '.a:dir
+  let output=system(a:cmd)
+  exe 'lcd '.cur_dir
+  return output
+endfunction</diff>
      <filename>.vim/plugin/github.vim</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,11 @@
-= github.vim
+= github.vim http://github.com/solars/github_vim/
 
-http://github.com/solars/github_vim/
+I tried to remove the dependency on drnics github-tmbundle scripts in this branch,
+please report any errors and feel free to correct/suggest/add.
 
 == Description
 
-This is a quick and dirty vim plugin to use with the scripts included in 
-github-tmbundle written by drnic, available at http://github.com/drnic/github-tmbundle
+This is a quick and dirty vim plugin to use some github features locally from vim.
 
 It enables you to:
   
@@ -14,7 +14,7 @@ It enables you to:
 
 == Suggested installation
 
-The file structure should be clear, root is your $HOME
+The file structure should be clear, just copy the github.vim into ~/.vim/plugin/
 
 == Usage
 
@@ -28,7 +28,5 @@ To remap the keybinding in your ~/.vimrc use:
 
 == Notes
 
-The files in /lib/drnic are contained in http://github.com/drnic/github-tmbundle, written by drnic.
-
-Since this is one of my first vim plugins, feel free to send corrections or improvements :)
+Since this is my first vim plugins, feel free to send corrections or improvements :)
 sol@textmode.at</diff>
      <filename>README</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>bin/github_comment.rb</filename>
    </removed>
    <removed>
      <filename>bin/github_open.rb</filename>
    </removed>
    <removed>
      <filename>lib/drnic/git-ext/commit.rb</filename>
    </removed>
    <removed>
      <filename>lib/drnic/git_manager.rb</filename>
    </removed>
    <removed>
      <filename>lib/drnic/show_in_github.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>d2b91387be6a88d87643c505d0ed611e7ed98310</id>
    </parent>
  </parents>
  <author>
    <name>Christoph Blank</name>
    <email>sol@textmode.at</email>
  </author>
  <url>http://github.com/solars/github-vim/commit/19d7b38c190bbe3eeedd1ef73d3c783a709ef560</url>
  <id>19d7b38c190bbe3eeedd1ef73d3c783a709ef560</id>
  <committed-date>2008-05-29T09:41:04-07:00</committed-date>
  <authored-date>2008-05-29T09:41:04-07:00</authored-date>
  <message>standalone vim plugin, moved github-tmbundle version into a seperate
branch</message>
  <tree>95d3f4eb4726ede0bd95f53506c3636114f37072</tree>
  <committer>
    <name>Christoph Blank</name>
    <email>sol@textmode.at</email>
  </committer>
</commit>
