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 | |
#coding:utf-8 | |
require 'pp' | |
require 'optparse' | |
opt = OptionParser.new | |
link=nil | |
begin | |
opt.on("-e", "--link","brew の gnuコマンドを/usr/local/bin にリンクします"){ link=true; } | |
opt.on("-d", "--unlink","brew の gnuコマンドを/usr/local/bin から削除します"){ link=false } | |
opt.parse!(ARGV) | |
if link.nil? | |
raise OptionParser::InvalidOption | |
end | |
rescue OptionParser::InvalidOption | |
ARGV << "-h" | |
retry | |
end | |
cmds = Dir.glob("/usr/local/opt/coreutils/libexec/gnubin/*").map{|e| e} | |
cmds.each{|e| | |
case link | |
when true | |
puts "link #{e} --> /usr/local/bin/#{File.basename e}\n" if link == true | |
File.unlink "/usr/local/bin/#{File.basename e}" if File.exist?("/usr/local/bin/#{File.basename e}") | |
File.symlink e, "/usr/local/bin/#{File.basename e}" | |
when false | |
puts "unlink /usr/local/bin/#{File.basename e}\n" if link == false | |
File.unlink "/usr/local/bin/#{File.basename e}" if link == false | |
end | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment