mate 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDQwY2I1MDBhOTNkYmM2YzI4YzgyOWQzZWYyMWJlMjM0YmE1MGY0MQ==
4
+ MzIwZmQ2ZThmODEzZTQ4NDA1MmJiMTdiZDZiNDg3NmE5MzFiYTQwNg==
5
5
  data.tar.gz: !binary |-
6
- NmYzMjUzOTMwOTlmMTdhNzg3YTJkN2NjN2RmMDgwYmRhYmVkNzhmOQ==
6
+ NjExZTBmMmU1MzY4NjFlYTNjNzU5YjlmZDNhOGVkZDIzYzhmZTI4Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDE1ZGRiODFjYWYyYjZmMDk5MzFmMGFlYTFiMjkxOTlkOWEwNGRmZTdlM2Uw
10
- ZWQyNjY3ZmQzNjk2ODdjYTQ0N2FjMmM2ODU2ZGQwNmUzMDE3NzViMGU2M2Ex
11
- OWY3MmFjMDdjMTAyNjBmYmEzNGQzZTM4OGNkOGZhYzViNWIyYjc=
9
+ M2VlYjU1ZmJjNjk4OWYyODFlNzdhZWM0MGZkMGM4MTYzMjY2ZWMwZmIwMjJl
10
+ ZjBjZGQ3OTEyOGQ5OWNjNjlkNjRjNWE2NjU2NzgwYWJmYTIyZTA2Y2NkYmQ1
11
+ NzYwOWNiNDI0ZTZhMTNmODIwMDhhY2UyZWUwNTZmODllNWM1NjY=
12
12
  data.tar.gz: !binary |-
13
- YmJjMjBiZTNhMGNmNjhjMTRmZGI5MTdmMWEyM2MyZDY2ZWM4MDYyYjI0NmU1
14
- OWE0YzJhODI0MWMwNWQwZWIxYWQ0ODUxMmFhMmMwNDkxYjhlYjk2YjUwMDQ5
15
- ZjExMjg1YWJmYWZlNWJkZWU3ZjMwN2VlMTVhMDA0MTlmM2JmMmE=
13
+ ZWY3OWI5NjljMzYwNzg0YjdmNGQ0YmQ2YmIzNDEwZDcxMTJhOWExMzA2NjA1
14
+ MDY1MGE1ODlmZjNmYzBjOGM1MDNjY2IzMjgwZDMxNmY4YTZiODJmZTVmZGQ1
15
+ OTA2N2Y4YWQwNTI4ZjBhYzhhZDRhNzBlNWIwZjA1MWY2NDhhNWE=
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ Makefile
10
10
  *.o
11
11
  *.bundle
12
12
  /tmp/
13
+ /.tm_properties
data/README.markdown CHANGED
@@ -1,10 +1,10 @@
1
1
  # mate
2
2
 
3
- TextMate project builder using git ignores for exclusions
3
+ TextMate project builder and TextMate 2 properties builder using git ignores for exclusions.
4
4
 
5
- You can add `alias mate='tm'` to your `.profile`, `.bash_profile` …
5
+ You can add `alias mate='tm'` or `alias mate='tm2'` to your `.profile`, `.bash_profile` …
6
6
 
7
- When `tm` command (or `mate` if aliased) is called with one or more paths and any of them is a directory, than project is created in `~/.tmprojs/` and opened. Its file and folder filters are built based on all types of git ignores (global, `.gitignore` and `.git/info/exclude`) and special `.tmignore` which works like other ignore files for project but doesn't affect git itself (you can use global `~/.tmignore` file), also `.git` folder and certain files (images, archives, media files, logs and some other binary files) are filtered.
7
+ When `tm` command (or `mate` if aliased) is called with one or more paths and any of them is a directory, than project is created in `~/.tmprojs/` and opened. When `tm2` command (or `mate` if aliased) is called with one or more paths, for all directories a `.tm_properties` file is generated or changed and mate is called. Its file and folder filters are built based on all types of git ignores (global, `.gitignore` and `.git/info/exclude`) and special `.tmignore` which works like other ignore files for project but doesn't affect git itself (you can use global `~/.tmignore` file), also `.git` folder and certain files (images, archives, media files, logs and some other binary files) are filtered.
8
8
 
9
9
  ## Copyright
10
10
 
data/bin/tm CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'mate'
3
+ require 'mate/bin'
4
+ require 'mate/tmproj'
4
5
 
5
6
  if !ARGV.empty? && ARGV.all?(&File.method(:exist?)) && ARGV.any?(&File.method(:directory?))
6
7
  Mate::Tmproj.new(ARGV).open
7
8
  else
8
- mate = (IO.popen('which -a mate', &:readlines).map(&:strip) - [__FILE__]).first
9
- system mate, *ARGV
9
+ system Mate::Bin.v1, *ARGV
10
10
  end
data/bin/tm2 ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mate/bin'
4
+ require 'mate/tm_properties'
5
+
6
+ ARGV.each do |arg|
7
+ if File.directory?(arg) && File.directory?(File.join(arg, '.git'))
8
+ Mate::TmProperties.new(arg).save
9
+ end
10
+ end
11
+
12
+ system Mate::Bin.v2, *ARGV
data/lib/mate/bin.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'shellwords'
2
+
3
+ module Mate
4
+ module Bin
5
+ class << self
6
+ def v1
7
+ mate_version(/^mate r\d+/) or abort 'Can\'t find mate binary v1'
8
+ end
9
+
10
+ def v2
11
+ mate_version(/^mate 2.\d+/) or abort 'Can\'t find mate binary v2'
12
+ end
13
+
14
+ private
15
+
16
+ def mate_version(regexp)
17
+ IO.popen('which -a mate', &:readlines).map(&:strip).find{ |bin| `#{bin.shellescape} -v` =~ regexp }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ module Mate
2
+ class TmProperties::Ignores
3
+ GENERATED_SUFFIX = "## GENERATED ##"
4
+ GENERATED_R = /^exclude(?:Directories)? = .* #{Regexp.escape(GENERATED_SUFFIX)}$/
5
+
6
+ attr_reader :dir
7
+ def initialize(dir)
8
+ @dir = dir
9
+ @exclude = ['**/.git']
10
+ @exclude_directories = []
11
+
12
+ process(dir, '.', Pathname(`git config --get core.excludesfile`.strip).expand_path)
13
+ process(dir, '.', Pathname('~/.tmignore').expand_path)
14
+
15
+ dir.find do |path|
16
+ if path.directory?
17
+ %w[.gitignore .tmignore .git/info/exclude].each do |ignore_file_name|
18
+ if (ignore_file = path + ignore_file_name).file?
19
+ process(dir, path.relative_path_from(dir).to_s, ignore_file)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def lines
27
+ escaped_dir = glob_escape(dir.to_s)
28
+ [
29
+ "exclude = '#{escaped_dir}/#{glob_join(@exclude)}' #{GENERATED_SUFFIX}",
30
+ "excludeDirectories = '#{escaped_dir}/#{glob_join(@exclude_directories)}' #{GENERATED_SUFFIX}",
31
+ ]
32
+ end
33
+
34
+ private
35
+
36
+ def process(parent, subdirectory, ignore_file)
37
+ return unless ignore_file.exist?
38
+
39
+ prefix = subdirectory == '.' ? '' : glob_escape("#{subdirectory}/")
40
+
41
+ ignore_file.readlines.map do |line|
42
+ line.lstrip[/(.*?)(\r?\n)?$/, 1] # this strange stuff strips line, but allows mac Icon\r files to be ignored
43
+ end.reject do |line|
44
+ line.empty? || line =~ /^\#/
45
+ end.each do |pattern|
46
+ negate = pattern.sub!(/^\!/, '')
47
+ unless pattern.sub!(/^\//, '')
48
+ pattern = "**/#{pattern}"
49
+ end
50
+ pattern = "#{prefix}#{pattern}"
51
+ list = (pattern.sub!(/\/$/, '') ? @exclude_directories : @exclude)
52
+ if negate
53
+ list.delete(pattern) # negation only works for exact matches
54
+ else
55
+ list << pattern
56
+ end
57
+ end
58
+ end
59
+
60
+ def glob_escape(string)
61
+ string.gsub(/([\*\?\[\]\{\}])/, '\\\\\1')
62
+ end
63
+
64
+ def glob_join(list)
65
+ list.length == 1 ? list : "{#{list.join(',')}}"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,30 @@
1
+ require 'pathname'
2
+
3
+ module Mate
4
+ class TmProperties
5
+ attr_reader :dir, :file
6
+ def initialize(dir)
7
+ @dir = Pathname(dir).expand_path
8
+ @file = @dir + '.tm_properties'
9
+ end
10
+
11
+ def save
12
+ ignores = Ignores.new(dir)
13
+
14
+ lines = if file.exist?
15
+ file.readlines.reject do |line|
16
+ line =~ Ignores::GENERATED_R
17
+ end
18
+ else
19
+ []
20
+ end
21
+
22
+ @file.open('w') do |f|
23
+ f.puts ignores.lines
24
+ f.puts lines
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'mate/tm_properties/ignores'
@@ -57,8 +57,9 @@ module Mate
57
57
  line.empty? || %w[# !].include?(line[0, 1])
58
58
  end.each do |line|
59
59
  pattern = glob2regexp(line)
60
- pattern = "#{DOUBLE_ASTERISK_R}#{pattern}" unless line['/']
61
- pattern.sub!(/^\//, '')
60
+ unless pattern.sub!(/^\//, '')
61
+ pattern = "#{DOUBLE_ASTERISK_R}#{pattern}"
62
+ end
62
63
  unless pattern.sub!(/\/$/, '')
63
64
  current_file_pattern << pattern
64
65
  end
data/mate.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mate'
5
- s.version = '1.3.0'
5
+ s.version = '2.0.0'
6
6
  s.summary = %q{TextMate project builder using git ignores for exclusions}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plist
@@ -28,6 +28,7 @@ description:
28
28
  email:
29
29
  executables:
30
30
  - tm
31
+ - tm2
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
34
  files:
@@ -35,7 +36,10 @@ files:
35
36
  - LICENSE.txt
36
37
  - README.markdown
37
38
  - bin/tm
38
- - lib/mate.rb
39
+ - bin/tm2
40
+ - lib/mate/bin.rb
41
+ - lib/mate/tm_properties.rb
42
+ - lib/mate/tm_properties/ignores.rb
39
43
  - lib/mate/tmproj.rb
40
44
  - lib/mate/tmproj/ignores.rb
41
45
  - mate.gemspec
data/lib/mate.rb DELETED
@@ -1 +0,0 @@
1
- require 'mate/tmproj'