Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created December 30, 2010 08:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/759598 to your computer and use it in GitHub Desktop.
Save hitode909/759598 to your computer and use it in GitHub Desktop.
rpwd
#!/usr/bin/env ruby
require 'pathname'
def path_diff from, to
Pathname.new(to).relative_path_from(Pathname.new(from)).to_s
end
def path_from_home path
path.gsub(ENV['HOME'], '~')
end
unless ARGV.length == 2
warn "usage: path_diff_ruby PATH1 PATH2"
exit 1
end
from, to = *ARGV
puts [path_diff(from, to), path_from_home(to), to].sort_by(&:length).first
# source rpwd in .zshrc
export __session_from=$PWD
function rpwd () {
path_diff.rb $__session_from $(pwd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment