mate 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ pkg
3
+ doc
4
+ *.gem
5
+ *.swp
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Boba Fat
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = mate
2
+
3
+ TextMate project builder using git ignores for exclusions
4
+
5
+
6
+
7
+ == Copyright
8
+
9
+ Copyright (c) 2010 Boba Fat. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'jeweler'
3
+
4
+ name = 'mate'
5
+
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = name
8
+ gem.summary = %Q{TextMate project builder using git ignores for exclusions}
9
+ gem.homepage = "http://github.com/toy/#{name}"
10
+ gem.authors = ['Boba Fat']
11
+ gem.add_dependency 'plist'
12
+ end
13
+
14
+ Jeweler::GemcutterTasks.new
15
+
16
+ require 'pathname'
17
+ desc "Replace system gem with symlink to this folder"
18
+ task 'ghost' do
19
+ gem_path = Pathname(Gem.searcher.find(name).full_gem_path)
20
+ current_path = Pathname('.').expand_path
21
+ system('rm', '-r', gem_path)
22
+ system('ln', '-s', current_path, gem_path)
23
+ end
24
+
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
27
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/bin/tm ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'mate'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'mate'
8
+ end
9
+
10
+ mate = (IO.popen('which -a mate', &:readlines).map(&:strip) - [__FILE__]).first
11
+
12
+ if !ARGV.empty? && ARGV.all?{ |arg| File.directory?(arg) }
13
+ Mate::Tmproj.new(ARGV).open
14
+ else
15
+ system mate, *ARGV
16
+ end
@@ -0,0 +1,72 @@
1
+ module Mate
2
+ class Tmproj::Ignores
3
+ BINARY_EXTENSIONS = [
4
+ %w[jpe?g png gif psd], # images
5
+ %w[zip tar t?(?:g|b)z], # archives
6
+ %w[mp3 mov], # media
7
+ %w[log tmp swf fla pdf], # other
8
+ ]
9
+ DOUBLE_ASTERISK_R = '(?:.+/)?'
10
+
11
+ attr_reader :dir, :file_pattern, :folder_pattern
12
+ def initialize(dir)
13
+ @dir = dir
14
+ @file_pattern = ["#{DOUBLE_ASTERISK_R}.+\\.(?:#{BINARY_EXTENSIONS.flatten.join('|')})"]
15
+ @folder_pattern = ["#{DOUBLE_ASTERISK_R}.git"]
16
+
17
+ add(dir, Pathname(`git config --get core.excludesfile`.strip))
18
+
19
+ dir.find do |path|
20
+ Find.prune if ignore?(path)
21
+ if path.directory? && (ignore_file = path + '.gitignore').file?
22
+ add(path, ignore_file)
23
+ end
24
+ end
25
+ end
26
+
27
+ def ignore?(path)
28
+ case
29
+ when path.file?
30
+ path =~ /#{file_r}/
31
+ when path.directory?
32
+ path =~ /#{folder_r}/
33
+ end
34
+ end
35
+
36
+ def file_r
37
+ "^#{Regexp.escape(dir)}/(?:#{file_pattern.join('|')})$"
38
+ end
39
+ def folder_r
40
+ "^#{Regexp.escape(dir)}/(?:#{folder_pattern.join('|')})$"
41
+ end
42
+
43
+ private
44
+
45
+ def add(parent, ignore_file)
46
+ current_file_pattern = []
47
+ current_folder_pattern = []
48
+ ignore_file.readlines.map do |line|
49
+ line.lstrip[/(.*?)(\r?\n)?$/, 1] # this strange stuff strips line, but allows mac Icon\r files to be ignored
50
+ end.reject do |line|
51
+ line.empty? || %w[# !].include?(line[0, 1])
52
+ end.each do |line|
53
+ pattern = Regexp.escape(line).gsub(/\\\*+/, '[^/]*') # understand only * pattern
54
+ pattern = "#{DOUBLE_ASTERISK_R}#{pattern}" unless line['/']
55
+ pattern.sub!(/^\//, '')
56
+ unless pattern.sub!(/\/$/, '')
57
+ current_file_pattern << pattern
58
+ end
59
+ current_folder_pattern << pattern
60
+ end
61
+ current_file_pattern = current_file_pattern.join('|')
62
+ current_folder_pattern = current_folder_pattern.join('|')
63
+ unless parent == dir
64
+ parent_pattern = Regexp.escape(parent.relative_path_from(dir))
65
+ current_file_pattern = "#{parent_pattern}/(?:#{current_file_pattern})"
66
+ current_folder_pattern = "#{parent_pattern}/(?:#{current_folder_pattern})"
67
+ end
68
+ file_pattern << current_file_pattern
69
+ folder_pattern << current_folder_pattern
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,66 @@
1
+ require 'pathname'
2
+ require 'digest/sha2'
3
+ require 'plist'
4
+
5
+ module Mate
6
+ class Tmproj
7
+ TMPROJ_DIR = Pathname('~').expand_path + '.tmprojs'
8
+
9
+ attr_reader :dirs, :file
10
+ def initialize(dirs)
11
+ @dirs = dirs.map{ |dir| Pathname(dir).expand_path }
12
+ @file = TMPROJ_DIR + [
13
+ Digest::SHA256.hexdigest(@dirs.join('-').downcase),
14
+ "#{common_dir(@dirs).basename}.tmproj"
15
+ ].join('/')
16
+ end
17
+
18
+ def open
19
+ data = Plist::parse_xml(file) rescue {}
20
+
21
+ data['documents'] = dirs.map do |dir|
22
+ ignores = Ignores.new(dir)
23
+ {
24
+ :expanded => true,
25
+ :name => dir.basename.to_s,
26
+ :regexFileFilter => "!#{ignores.file_r}",
27
+ :regexFolderFilter => "!#{ignores.folder_r}",
28
+ :sourceDirectory => dir.to_s
29
+ }
30
+ end
31
+ data['fileHierarchyDrawerWidth'] ||= 269
32
+ data['metaData'] ||= {}
33
+ data['showFileHierarchyDrawer'] = true unless data.has_key?('showFileHierarchyDrawer')
34
+ dimensions = IO.popen(%q{osascript -e 'tell application "Finder" to get bounds of window of desktop'}, &:read).scan(/\d+/).map(&:to_i)
35
+ data['windowFrame'] ||= "{{#{dimensions[0] + 100}, #{dimensions[1] + 50}}, {#{dimensions[2] - 200}, #{dimensions[3] - 100}}}"
36
+
37
+ file.dirname.mkpath
38
+ file.open('w'){ |f| f.write(data.to_plist) }
39
+
40
+ system 'open', file
41
+ end
42
+
43
+ private
44
+
45
+ def common_dir(paths)
46
+ common = nil
47
+ paths.each do |path|
48
+ if path.file?
49
+ path = path.dirname
50
+ end
51
+ ascendants = []
52
+ path.ascend do |ascendant|
53
+ ascendants << ascendant
54
+ end
55
+ unless common
56
+ common = ascendants
57
+ else
58
+ common &= ascendants
59
+ end
60
+ end
61
+ common && common.first
62
+ end
63
+ end
64
+ end
65
+
66
+ require 'mate/tmproj/ignores'
data/lib/mate.rb ADDED
@@ -0,0 +1 @@
1
+ require 'mate/tmproj'
data/mate.gemspec ADDED
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mate}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Boba Fat"]
12
+ s.date = %q{2010-11-08}
13
+ s.default_executable = %q{tm}
14
+ s.executables = ["tm"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/tm",
26
+ "lib/mate.rb",
27
+ "lib/mate/tmproj.rb",
28
+ "lib/mate/tmproj/ignores.rb",
29
+ "mate.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/toy/mate}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{TextMate project builder using git ignores for exclusions}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<plist>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<plist>, [">= 0"])
45
+ end
46
+ else
47
+ s.add_dependency(%q<plist>, [">= 0"])
48
+ end
49
+ end
50
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Boba Fat
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-08 00:00:00 +03:00
19
+ default_executable: tm
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: plist
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email:
37
+ executables:
38
+ - tm
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - bin/tm
51
+ - lib/mate.rb
52
+ - lib/mate/tmproj.rb
53
+ - lib/mate/tmproj/ignores.rb
54
+ - mate.gemspec
55
+ has_rdoc: true
56
+ homepage: http://github.com/toy/mate
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: TextMate project builder using git ignores for exclusions
89
+ test_files: []
90
+