pocketwatch 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +73 -0
- data/LICENSE.txt +21 -0
- data/README.md +19 -0
- data/Rakefile +1 -0
- data/bin/pocketwatch +5 -0
- data/lib/pocketwatch/version.rb +3 -0
- data/lib/pocketwatch/watcher.rb +55 -0
- data/lib/pocketwatch.rb +46 -0
- data/pocketwatch.gemspec +29 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5388ad0287b782cbfcbd2fd09befcca9f0103d8b415cf60e2cc19b0016c64bbf
|
4
|
+
data.tar.gz: 627a66a496dd946cb70975d9861e5c2be3b2a77773a5d9a52a6dd525e264de98
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb3d6d5b7abb3a4feee7c241ddc261116a0b7d46a6d286f2127f83ace85cc899d38e54d993dee5da5db104d70fedefc37ece19e16d2f87071f10c37c990c4216
|
7
|
+
data.tar.gz: d7bf7e1e7f854a299f03b69320eb1710082e6deb1956218d740ac7459a7e54e5d08e52197c66f2ef9dca98c6e838dffd20afd22ed9bf934a279cdbe1404a8829
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.5
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pocketwatch (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
backport (1.1.2)
|
11
|
+
benchmark (0.1.0)
|
12
|
+
byebug (11.0.1)
|
13
|
+
coderay (1.1.2)
|
14
|
+
e2mmap (0.1.0)
|
15
|
+
jaro_winkler (1.5.4)
|
16
|
+
maruku (0.7.3)
|
17
|
+
method_source (0.9.2)
|
18
|
+
mini_portile2 (2.4.0)
|
19
|
+
nokogiri (1.10.7)
|
20
|
+
mini_portile2 (~> 2.4.0)
|
21
|
+
parallel (1.19.1)
|
22
|
+
parser (2.7.0.2)
|
23
|
+
ast (~> 2.4.0)
|
24
|
+
pry (0.12.2)
|
25
|
+
coderay (~> 1.1.0)
|
26
|
+
method_source (~> 0.9.0)
|
27
|
+
pry-byebug (3.7.0)
|
28
|
+
byebug (~> 11.0)
|
29
|
+
pry (~> 0.10)
|
30
|
+
rainbow (3.0.0)
|
31
|
+
rake (12.3.3)
|
32
|
+
reverse_markdown (1.4.0)
|
33
|
+
nokogiri
|
34
|
+
rubocop (0.79.0)
|
35
|
+
jaro_winkler (~> 1.5.1)
|
36
|
+
parallel (~> 1.10)
|
37
|
+
parser (>= 2.7.0.1)
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
41
|
+
ruby-progressbar (1.10.1)
|
42
|
+
rufo (0.10.0)
|
43
|
+
solargraph (0.38.2)
|
44
|
+
backport (~> 1.1)
|
45
|
+
benchmark
|
46
|
+
bundler (>= 1.17.2)
|
47
|
+
e2mmap
|
48
|
+
jaro_winkler (~> 1.5)
|
49
|
+
maruku (~> 0.7, >= 0.7.3)
|
50
|
+
nokogiri (~> 1.9, >= 1.9.1)
|
51
|
+
parser (~> 2.3)
|
52
|
+
reverse_markdown (~> 1.0, >= 1.0.5)
|
53
|
+
rubocop (~> 0.52)
|
54
|
+
thor (~> 1.0)
|
55
|
+
tilt (~> 2.0)
|
56
|
+
yard (~> 0.9)
|
57
|
+
thor (1.0.1)
|
58
|
+
tilt (2.0.10)
|
59
|
+
unicode-display_width (1.6.1)
|
60
|
+
yard (0.9.24)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
pocketwatch!
|
67
|
+
pry-byebug
|
68
|
+
rake (~> 12.0)
|
69
|
+
rufo
|
70
|
+
solargraph
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.1.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Taylor Thurlow
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Pocketwatch
|
2
|
+
|
3
|
+
`pocketwatch` is a clone of the `watch` utility found on many UNIX-based operating systems. It exists entirely due to the fact that `watch` swallows CTRL-code shortcuts that aren't CTRL-C (interrupt), and as a result, makes it really difficult to use CTRL codes to navigate around terminal panes. A Ruby implementation serves the same purpose but doesn't jack up my terminal navigation.
|
4
|
+
|
5
|
+
Yes, that's the only reason this exists.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem install pocketwatch
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
TODO: Write usage instructions here
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/pocketwatch
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Pocketwatch
|
2
|
+
class Watcher
|
3
|
+
# @return [String] the command to run on an interval
|
4
|
+
attr_reader :command
|
5
|
+
|
6
|
+
# @return [Hash] the options hash determined by the command-line option
|
7
|
+
# parser
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
# @param command [String] the command to run on an interval
|
11
|
+
# @param options [Hash] the options hash determined by the command-line
|
12
|
+
# option parser
|
13
|
+
def initialize(command, options = {})
|
14
|
+
@command = command
|
15
|
+
|
16
|
+
if @command.nil? || @command.empty?
|
17
|
+
warn "No command provided."
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
@options = options
|
21
|
+
end
|
22
|
+
|
23
|
+
# Begin the watcher task, executing the provided command in a loop. The
|
24
|
+
# loop will only break when interrupted in the shell.
|
25
|
+
#
|
26
|
+
# @return [void]
|
27
|
+
def run
|
28
|
+
loop do
|
29
|
+
# Double buffer the output by precomputing the results of the system
|
30
|
+
# call. Then, clear the terminal and print the results as quickly as
|
31
|
+
# possible - this should avoid any flickering due to clearing the
|
32
|
+
# terminal.
|
33
|
+
output = `#{@command}`
|
34
|
+
|
35
|
+
clear_screen
|
36
|
+
puts output
|
37
|
+
|
38
|
+
sleep(@options[:interval] || 2)
|
39
|
+
end
|
40
|
+
rescue Errno::EPIPE, SystemExit, Interrupt
|
41
|
+
clear_screen
|
42
|
+
exit 0
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Clear the terminal screen by writing a control code to the terminal. This
|
48
|
+
# avoids having to shell out to run something like `clear`.
|
49
|
+
#
|
50
|
+
# @return [void]
|
51
|
+
def clear_screen
|
52
|
+
puts "\e[H\e[2J"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/pocketwatch.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
require_relative "pocketwatch/watcher"
|
4
|
+
|
5
|
+
module Pocketwatch
|
6
|
+
# Parse the ARGV input and run the command watcher.
|
7
|
+
#
|
8
|
+
# @param args [Array<String>] the array of input arguments, typically `ARGV`
|
9
|
+
#
|
10
|
+
# @return [void]
|
11
|
+
def self.start(args)
|
12
|
+
options = parse(args)
|
13
|
+
Watcher.new(args.join(" "), options).run
|
14
|
+
end
|
15
|
+
|
16
|
+
# Parse an argument list for configuration options
|
17
|
+
#
|
18
|
+
# @param args [Array<String>] the array of input arguments, typically `ARGV`
|
19
|
+
#
|
20
|
+
# @return [Hash] the options hash
|
21
|
+
def self.parse(args)
|
22
|
+
options = {}
|
23
|
+
|
24
|
+
parser = OptionParser.new do |opts|
|
25
|
+
opts.banner = "Usage: pocketwatch [options] -- <command>"
|
26
|
+
|
27
|
+
opts.on("-v", "--version", "Print the version number") do
|
28
|
+
puts Pocketwatch::VERSION
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("-n INTERVAL", Integer, "Interval length in seconds between command execution") do |v|
|
33
|
+
unless v.positive?
|
34
|
+
warn "Must provide a positive integer for the command execution interval."
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
options[:interval] = v
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
parser.parse!(args)
|
43
|
+
|
44
|
+
options
|
45
|
+
end
|
46
|
+
end
|
data/pocketwatch.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require_relative "lib/pocketwatch/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "pocketwatch"
|
7
|
+
spec.version = Pocketwatch::VERSION
|
8
|
+
spec.authors = ["Taylor Thurlow"]
|
9
|
+
spec.email = ["taylorthurlow@me.com"]
|
10
|
+
|
11
|
+
spec.summary = "A clone of UNIX 'watch'."
|
12
|
+
spec.homepage = "https://github.com/taylorthurlow/pocketwatch"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/taylorthurlow/pocketwatch/releases"
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split
|
21
|
+
spec.bindir = "bin"
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "pry-byebug"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rufo"
|
28
|
+
spec.add_development_dependency "solargraph"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pocketwatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taylor Thurlow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry-byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rufo
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: solargraph
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- taylorthurlow@me.com
|
72
|
+
executables:
|
73
|
+
- pocketwatch
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".ruby-version"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/pocketwatch
|
85
|
+
- lib/pocketwatch.rb
|
86
|
+
- lib/pocketwatch/version.rb
|
87
|
+
- lib/pocketwatch/watcher.rb
|
88
|
+
- pocketwatch.gemspec
|
89
|
+
homepage: https://github.com/taylorthurlow/pocketwatch
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata:
|
93
|
+
homepage_uri: https://github.com/taylorthurlow/pocketwatch
|
94
|
+
source_code_uri: https://github.com/taylorthurlow/pocketwatch
|
95
|
+
changelog_uri: https://github.com/taylorthurlow/pocketwatch/releases
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.5.0
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.6.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: A clone of UNIX 'watch'.
|
116
|
+
test_files: []
|