-
-
Save nisshiee/ad804ba5c5eb07fe00d566c0220a2503 to your computer and use it in GitHub Desktop.
ちょっと賢いsublコマンド
This file contains hidden or 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 | |
SUBL_COMMAND = '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' | |
require 'pathname' | |
def base_dir | |
return @base_dir if @base_dir | |
return @base_dir = Pathname.new('.') if ARGV.empty? | |
input = Pathname.new(ARGV[0]) | |
return @base_dir = input if input.directory? | |
parent = input.parent | |
return @base_dir = parent if parent.directory? | |
puts 'WARN: target directory does NOT exist' | |
@base_dir = Pathname.new('.') | |
end | |
def detected_target | |
base_dir.each_child(false) do |file| | |
return @detected_target = file if file.fnmatch?('*.sublime-project') | |
end | |
@detected_target = base_dir | |
end | |
system(SUBL_COMMAND, detected_target.to_s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment