rta 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -13
  2. data/bin/rta +82 -50
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTgwODRmZTc3ODgwZDY0MDhjODcwYTk2NDk0NzI3MDNmMmNkMWRmNg==
5
- data.tar.gz: !binary |-
6
- ZDEzMDgwMjFiMjA3OGNkZjQ0MDIxYmU2NTBjOWNmZjZkZGM3OTdmOQ==
2
+ SHA1:
3
+ metadata.gz: 5aa3be2ea81a425cad1bd05e10cc81818af79f5e
4
+ data.tar.gz: c9a6ce480d52e9a97947278c146e9394b2872baf
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjlmYjI5NjNhMWFmZmIwNWJiZjRhOTFlODYyZmM3ZGM4YmUwNGE4OGYwZDY5
10
- YTFjMTE3NDcxZjIzNjc5MDI5ZjFiN2NjMjJkODdkYzE4MTFmZGU5ZTU4NWJh
11
- MDM0NmNlMGNlMmRmOGQ1MjQ5ZGI2OWMzMjRiNzI1ZTFmMTQ5NTg=
12
- data.tar.gz: !binary |-
13
- OWM0Y2ZkNmUzYmM2ZjQzZTc4NWQzZmRhODkwYTAxZjk4ZjU0YWM1MmMyYTg4
14
- OGVhY2EzMDcyMzkwMmIxYzUyNTRhMzk2YTZmMzg2ZTVjODM0OTcxYTQ5OTFj
15
- ZTA2OWUxNzIxODAzZTUzZWI4M2Y4ZGZlOTlmNTViNjVjZTg4NDY=
6
+ metadata.gz: 43a9fc70a44ee6776cd28337236083896d33ce4c0c7b5db6ab11dfe3057cacb913c736ceedcc3e1c766080ae84179401f11b510704c6ddb8e1ace5c09b6b0afa
7
+ data.tar.gz: 755c307840d5dc4507d3803b88ac9facc0c4849bfa2c169c3e1d9cc9cbb9d8500806f8bf9a2be88ccb7767ba89f517c3579174622b00debae19ed4003e78c98a
data/bin/rta CHANGED
@@ -1,77 +1,109 @@
1
- #! /usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'rb-fsevent'
4
4
  require 'optparse'
5
5
 
6
- options = {}
6
+ options = {:sleep => 0}
7
7
  excludes = []
8
8
  includes = []
9
9
  verbose = false
10
10
 
11
11
  opts = OptionParser.new do |opts|
12
- opts.banner = "Run a command when contents in this directory change.\nUsage: #{File.basename(__FILE__)} [-n|--no-clear] <command>"
13
- opts.on("-n", "--[no-]clear", "Don't clear the screen before execution") do |n|
14
- options[:no_clear] = n
15
- end
16
- opts.on("-v", "--[no-]verbose", "Be verbose in outputing match decisions") do |v|
17
- verbose = v
18
- end
19
- opts.on("-i", "--include-dir DIRECTORY", "Watch the given directory for changes only. The value should be relative to the current working directory. Can be set multiple times.") do |d|
20
- includes.push(File.expand_path(d, Dir.pwd) + "/")
21
- end
22
- opts.on("-e", "--exclude-dir DIRECTORY", "Ignore the given directory when its contents change. The value should be relative to the current working directory.") do |d|
23
- excludes.push(File.expand_path(d, Dir.pwd) + "/")
24
- end
25
- opts.on_tail("-h", "--help", "Show help") do
26
- puts opts
27
- exit
28
- end
12
+ opts.banner = "Run a command when contents in this directory change.\nUsage: #{File.basename(__FILE__)} [-n|--no-clear] <command>"
13
+ opts.on("-n", "--[no-]clear", "Don't clear the screen before execution") do |n|
14
+ options[:no_clear] = n
15
+ end
16
+ opts.on("-v", "--[no-]verbose", "Be verbose in outputing match decisions") do |v|
17
+ verbose = v
18
+ end
19
+ opts.on("-i", "--include-dir DIRECTORY", "Watch the given directory for changes only. The value should be relative to the current working directory. Can be set multiple times.") do |d|
20
+ includes.push(File.expand_path(d, Dir.pwd) + "/")
21
+ end
22
+ opts.on("-e", "--exclude-dir DIRECTORY", "Ignore the given directory when its contents change. The value should be relative to the current working directory.") do |d|
23
+ excludes.push(File.expand_path(d, Dir.pwd) + "/")
24
+ end
25
+ opts.on("-s", "--sleep", "Sleep for a second after running the command. This can help prevent infinite loops") do
26
+ options[:sleep] = 1
27
+ end
28
+ opts.on_tail("-h", "--help", "Show help") do
29
+ puts opts
30
+ exit
31
+ end
29
32
 
30
33
  end
31
34
  opts.parse!
32
35
 
33
36
  command = ARGV.join(" ")
34
37
  if command == ""
35
- $stderr.puts "no command specified :("
36
- puts opts
37
- exit 1
38
+ $stderr.puts "no command specified :("
39
+ puts opts
40
+ exit 1
38
41
  end
39
42
 
40
43
  unless options[:no_clear]
41
- command = "clear && #{command}"
44
+ command = "clear && #{command}"
42
45
  end
43
46
 
47
+ # run once at the begining
48
+ system command
49
+
50
+ active_thread = nil
51
+
52
+ # Trapping INT lets ctrl-C terminate
53
+ # the thread running the underlying call
54
+
55
+ Signal.trap("SIGINT") do
56
+ if active_thread
57
+ active_thread.kill
58
+ active_thread = nil
59
+ $stderr.puts "rta: killed active thread\n"
60
+ set_title "rta: waiting"
61
+ else
62
+ exit
63
+ end
64
+ end
65
+
66
+ def set_title(str)
67
+ print "\033]0;#{str}\007"
68
+ end
69
+
70
+ set_title "rta: waiting"
71
+
44
72
  fsevent = FSEvent.new
45
73
  active = false
46
74
  fsevent.watch Dir.pwd do |directories|
47
- skip = true
48
- directories.each do |d|
49
- if excludes.include? d
50
- puts "excluding #{d}" if verbose
51
- else
52
- skip = false
53
- puts "#{excludes} does not contain #{d}" if verbose
54
- end
55
- end
75
+ skip = true
76
+ directories.each do |d|
77
+ if excludes.include? d
78
+ puts "excluding #{d}" if verbose
79
+ else
80
+ skip = false
81
+ puts "#{excludes} does not contain #{d}" if verbose
82
+ end
83
+ end
56
84
 
57
- directories.each do |d|
58
- if includes.include? d
59
- skip = false
60
- puts "including #{d}" if verbose
61
- else
62
- puts "#{includes} does not contain #{d}" if verbose
63
- end
64
- end
85
+ directories.each do |d|
86
+ if includes.include? d
87
+ skip = false
88
+ puts "including #{d}" if verbose
89
+ else
90
+ puts "#{includes} does not contain #{d}" if verbose
91
+ end
92
+ end
65
93
 
66
- if not active and not skip
67
- active = true
68
- Thread.new do
69
- system command
70
- active = false
71
- end
72
- elsif verbose
73
- puts "did not execute - command is active" if active
74
- puts "did not execute - command was skipped" if skip
75
- end
94
+ if !(active || skip)
95
+ active = true
96
+ active_thread = Thread.new do
97
+ set_title "rta: running #{command}"
98
+ system command
99
+ sleep options[:sleep]
100
+ active = false
101
+ active_thread = nil
102
+ set_title "rta: waiting"
103
+ end
104
+ elsif verbose
105
+ puts "did not execute - command is active" if active
106
+ puts "did not execute - command was skipped" if skip
107
+ end
76
108
  end
77
109
  fsevent.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bishopric
@@ -44,12 +44,12 @@ require_paths:
44
44
  - lib
45
45
  required_ruby_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ! '>='
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
@@ -57,5 +57,5 @@ rubyforge_project:
57
57
  rubygems_version: 2.2.2
58
58
  signing_key:
59
59
  specification_version: 4
60
- summary: Run a script repeatedly when the working directory changes
60
+ summary: Run This Again.
61
61
  test_files: []