rpwdã£ã¦ããã³ãã³ããä½ã£ãï¼pwdã®ï¼åºåçµæããªãã¹ãçããªãããã«ãããã¤ï¼äººãè¦ãã®ã«ä½¿ãï¼
% rpwd
.
% cd lib
% rpwd
lib
rpwdã¯ï¼ã·ã§ã«ãèµ·åããç¬éã®ãã¹(以ä¸ï¼åºæºãã¹)ã使ã£ã¦ï¼çãpwdãä½ãï¼
åºæºãã¹ããã®ç¸å¯¾ãã¹ã¨ãï¼ãã¼ã ãã£ã¬ã¯ããªã¾ã§ã®ãã¹ã~ã«ãããã®ã¨ãï¼çµ¶å¯¾ãã¹ã¨ããè¦ã¦ï¼ä¸çªçãã®ãæ¡ç¨ããï¼
åºæºãã¹ã¯ï¼æ®éã«ã·ã§ã«ãèµ·åããã¨ãã¼ã ãã£ã¬ã¯ããªã ãã©ï¼screenå
ã§ã¯ï¼screenã®ã«ã¼ãã¿ãããªãã¹ã«ãªãï¼
ä¾ãã°ï¼åºæºãã¹ã/Users/fkd/co/kindairbã®ã¨ãï¼ä»¥ä¸ã®ããã«æ¯ãèãï¼
pwd | rpwd |
---|---|
/Users/fkd/co/kindairb | . |
/Users/fkd/co/kindairb/lib/kindai | lib/kindai |
/Users/fkd/co | .. |
/Users/fkd | ~ |
/etc | /etc |
.zshrcã¨ãã§source rpwdããã¨rpwdã³ãã³ããå®ç¾©ãããï¼ãã®ãã¡ã¤ã«ã¯ï¼èªã¿è¾¼ã¾ããã¨ãã®pwdã$__session_fromã£ã¦ããç°å¢å¤æ°ã«è¨é²ãã¦ãï¼
path_diff.rbã«ï¼$__session_fromã¨pwdã渡ãï¼
export __session_from=$PWD function rpwd () { path_diff.rb $__session_from $(pwd) }
path_diff.rbã¯ãã¹ã2ã¤åãåã£ã¦çãpwdã表示ããï¼PATHã®éã£ãã¨ããã«ç½®ãã¦ããï¼
#!/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
screenã®ã¿ã¤ãã«ã«pwdãåºãããã«ä½ã£ãï¼ã¿ã¤ãã«ã«pwdãåºãã¨é·ãã¦ä¸æå¿«ã ãã©ããããããªãæ°ã«ãªããªãï¼
Githubã«ç½®ãã¦ããï¼