Created
December 30, 2010 08:34
-
-
Save hitode909/759598 to your computer and use it in GitHub Desktop.
rpwd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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