no_tbj 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ee18be1f3ba8529f3c6f730687251a2e1aee7ac13269ee4bdda97cbd7d96c1c8
4
+ data.tar.gz: 2c82b15ff105a308063287ede46b8033c04c6459b88af61c8fe07e9727081f78
5
+ SHA512:
6
+ metadata.gz: 5b26433343fe7535b34052c2e9a9a3d911df56935153b06c186ce54cec36fad3a40572e663a7c766008bd9f2a21b26cbb68d096bdb3ae5be5be81e6837f78e6a
7
+ data.tar.gz: f66c82ab827cf4b20e02268d7b23847e8926854a942e39cf50aecd1cd307d38b77cf2363415fb9d293c5a2e1dfb74af733c6114ddea03524c902c76d2d78c985
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ lib/no_tbj/runner.exe
11
+ lib/no_tbj/runner_gemlib.exe
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-13
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ no_tbj (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (13.0.6)
10
+
11
+ PLATFORMS
12
+ x86-mingw32
13
+
14
+ DEPENDENCIES
15
+ no_tbj!
16
+ rake (~> 13.0)
17
+
18
+ BUNDLED WITH
19
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 sevenc-nanashi
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,45 @@
1
+ # NoTBJ
2
+
3
+ No more `Terminate Batch Job (Y/N)` prompts!
4
+ This gem is only for windows.
5
+
6
+ ## Installation
7
+
8
+ <!--
9
+ Execute this:
10
+ ```
11
+ > gem install no_tbj
12
+ ```
13
+
14
+ -->
15
+ This gem is not on rubygems.org, so you need to install it manually.
16
+
17
+ ```
18
+ git clone git@github.com:sevenc-nanashi/no_tbj.git
19
+ cd no_tbj
20
+ rake go
21
+ gem build no_tbj.gemspec
22
+ gem install no_tbj-x.x.x.gem
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ `no_tbj install` to install the executable.
28
+ `no_tbj uninstall` to uninstall the executable.
29
+ Just it, you won't be prompted to terminate the batch job!
30
+
31
+ ## Development
32
+
33
+ To build executable, execute `rake go`. Note `no_tbj` is added at the last of executable.
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sevenc-nanashi/no_tbj
42
+
43
+ ## License
44
+
45
+ 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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
5
+
6
+ namespace :go do
7
+ task :build do
8
+ File.delete("./lib/no_tbj/runner.exe") if File.exist?("./lib/no_tbj/runner.exe")
9
+ sh "go build -o ./lib/no_tbj/runner.exe ./go/runner.go"
10
+ File.delete("./lib/no_tbj/runner_gemlib.exe") if File.exist?("./lib/no_tbj/runner_gemlib.exe")
11
+ sh "go build -o ./lib/no_tbj/runner_gemlib.exe ./go/runner_gemlib.go"
12
+ end
13
+
14
+ task :modify do
15
+ require_relative "lib/no_tbj"
16
+ File.open("./lib/no_tbj/runner.exe", "ab") do |f|
17
+ f.write(NoTBJ::CHECKS)
18
+ end
19
+ File.open("./lib/no_tbj/runner_gemlib.exe", "ab") do |f|
20
+ f.write(NoTBJ::CHECKS)
21
+ end
22
+ end
23
+ end
24
+
25
+ task go: %i[go:build go:modify]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "no_tbj"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/no_tbj ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "no_tbj"
4
+
5
+ NoTBJ::CLI.new.run
data/go/runner.go ADDED
@@ -0,0 +1,30 @@
1
+ package main
2
+
3
+ import (
4
+ "os"
5
+ "os/exec"
6
+ "os/signal"
7
+ "path"
8
+ "strings"
9
+ "syscall"
10
+ )
11
+
12
+ func main() {
13
+ executable, _ := os.Executable()
14
+ executable = strings.Replace(executable, "\\", "/", -1)
15
+ trap := make(chan os.Signal, 1)
16
+ signal.Notify(trap, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
17
+ go func() {
18
+ <-trap
19
+ // Do nothing
20
+ }()
21
+ args := os.Args
22
+ base := executable[:len(executable)-4]
23
+ args[0] = base
24
+ directory := path.Dir(base)
25
+ cmd := exec.Command(directory+"/ruby.exe", args...)
26
+ cmd.Stdout = os.Stdout
27
+ cmd.Stderr = os.Stderr
28
+ cmd.Stdin = os.Stdin
29
+ cmd.Run()
30
+ }
@@ -0,0 +1,30 @@
1
+ package main
2
+
3
+ import (
4
+ "os"
5
+ "os/exec"
6
+ "os/signal"
7
+ "path"
8
+ "strings"
9
+ "syscall"
10
+ )
11
+
12
+ func main() {
13
+ executable, _ := os.Executable()
14
+ executable = strings.Replace(executable, "\\", "/", -1)
15
+ trap := make(chan os.Signal, 1)
16
+ signal.Notify(trap, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
17
+ go func() {
18
+ <-trap
19
+ // Do nothing
20
+ }()
21
+ args := os.Args
22
+ base := executable[:len(executable)-4]
23
+ args[0] = base
24
+ directory := path.Dir(base)
25
+ cmd := exec.Command(directory+"/../../../../../bin/ruby.exe", args...)
26
+ cmd.Stdout = os.Stdout
27
+ cmd.Stderr = os.Stderr
28
+ cmd.Stdin = os.Stdin
29
+ cmd.Run()
30
+ }
@@ -0,0 +1,38 @@
1
+ module NoTBJ::Color
2
+ refine String do
3
+ def red
4
+ colorize(31)
5
+ end
6
+
7
+ def green
8
+ colorize(32)
9
+ end
10
+
11
+ def blue
12
+ colorize(94)
13
+ end
14
+
15
+ def yellow
16
+ colorize(33)
17
+ end
18
+
19
+ def gray
20
+ colorize(37)
21
+ end
22
+
23
+ alias error red
24
+ alias success green
25
+ alias info blue
26
+ alias warn yellow
27
+ alias minfo gray
28
+
29
+ def colorize(color_code)
30
+ if color_code == 90
31
+ bright = 37
32
+ else
33
+ bright = color_code + 60
34
+ end
35
+ "\033[#{color_code}m#{self}\033[0m".gsub(/\{(.*?)\}/) { |m| "\033[#{bright}m#{$1}\033[#{color_code}m" }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,191 @@
1
+ require "rbconfig"
2
+ require "fileutils"
3
+ require_relative "color"
4
+
5
+ module NoTBJ
6
+ using NoTBJ::Color
7
+ CHECKS = "no_tbj"
8
+
9
+ class CLI
10
+ def run
11
+ if ARGV.empty?
12
+ puts "No arguments given.".red
13
+ puts "Please specify a command, {no_tbj help} for more information.".minfo
14
+ exit
15
+ end
16
+ case ARGV[0]
17
+ when "install"
18
+ install
19
+ when "uninstall"
20
+ uninstall
21
+ when "help"
22
+ show_help
23
+ when "info"
24
+ show_info
25
+ else
26
+ puts "Unrecognized command.".red
27
+ end
28
+ end
29
+
30
+ def install
31
+ files = { skipped_exist: [], skipped_nobat: [], skipped_exception: [], installed: [] }
32
+ add_bundler_script unless File.exist?(File.join(RbConfig::CONFIG["bindir"], "bundler"))
33
+ force_level = ARGV.count("-f")
34
+ verbose_level = ARGV.count("-v")
35
+ bindirs.each do |bindir|
36
+ Dir.glob(File.join(bindir, "*")).each do |file|
37
+ next if File.directory?(file)
38
+ next if File.fnmatch?("*.*", File.basename(file))
39
+
40
+ if File.exist?(file + ".exe") && force_level < 1
41
+ next files[:skipped_exist] << file
42
+ end
43
+ unless [
44
+ File.exist?(file + ".bat"), File.exist?(file + ".cmd"),
45
+ ].any?
46
+ files[:skipped_nobat] << file
47
+ puts "Could not find bat file for #{file}".minfo
48
+ next
49
+ end
50
+
51
+ begin
52
+ if File.read(Dir.glob(file + ".{bat,cmd}")[0]).include?("../../../../../bin/")
53
+ FileUtils.cp(exepath_gemlib, file + ".exe")
54
+ else
55
+ FileUtils.cp(exepath, file + ".exe")
56
+ end
57
+ rescue => e
58
+ if verbose_level > 0
59
+ puts "Failed to copy {#{exepath}} to {#{file}.exe}.".red
60
+ puts (verbose_level > 1 ? e.full_message : e.message).lines.map { |l| " " + l }.join
61
+ end
62
+ files[:skipped_exception] << file
63
+ else
64
+ files[:installed] << file
65
+ end
66
+ end
67
+ end
68
+ files = files.map { |k, v| [k, v.map { |f| File.basename(f) }] }.to_h
69
+ puts "Installed for {#{files[:installed].length}} files.".green
70
+ puts "Skipped {#{files[:skipped_exist].length}} files because they already exist, use {-f} to overwrite.".minfo unless files[:skipped_exist].empty?
71
+ puts "Skipped {#{files[:skipped_nobat].length}} files because they don't have a bat or cmd file.".minfo unless files[:skipped_nobat].empty?
72
+ unless files[:skipped_exception].empty?
73
+ puts "Skipped {#{files[:skipped_exception].length}} files because of an exception.".warn
74
+ puts "This usually occurs that the executable is already installed and running.".minfo
75
+ end
76
+ end
77
+
78
+ def uninstall
79
+ files = { skipped_notnotbj: [], skipped_exception: [], uninstalled: [] }
80
+ verbose_level = ARGV.count("-v")
81
+ tbj_executables.each do |file|
82
+ next if File.directory?(file)
83
+ begin
84
+ FileUtils.rm(file)
85
+ rescue => e
86
+ if verbose_level > 0
87
+ puts "Failed to remove {#{file}}.".red
88
+ puts (verbose_level > 1 ? e.full_message : e.message).lines.map { |l| " " + l }.join
89
+ end
90
+ files[:skipped_exception] << file
91
+ else
92
+ files[:uninstalled] << file
93
+ end
94
+ end
95
+
96
+ files = files.map { |k, v| [k, v.map { |f| File.basename(f) }] }.to_h
97
+ puts "Uninstalled {#{files[:uninstalled].length}} files.".success
98
+ unless files[:skipped_exception].empty?
99
+ puts "Skipped {#{files[:skipped_exception].length}} files because of an exception.".minfo
100
+ puts "This usually occurs that the executable is running.".minfo
101
+ end
102
+ end
103
+
104
+ def show_help
105
+ puts "no_tbj lets you ignore {`Terminate Batch Job (Y/N)`} dialogs.".green
106
+ puts "It installs executable to your Ruby's executable directory."
107
+ puts "{install:}".green
108
+ puts " no_tbj install".info
109
+ puts " You can specify {-f} to overwrite existing files.".minfo
110
+ puts " You can specify {-v} to show verbose output.".minfo
111
+ puts "{uninstall:}".green
112
+ puts " no_tbj uninstall".info
113
+ puts " You can specify {-v} to show verbose output.".minfo
114
+ puts "{info:}".green
115
+ puts " no_tbj info".info
116
+ puts " Shows some information.".minfo
117
+ end
118
+
119
+ def show_info
120
+ puts "no_tbj version: {#{NoTBJ::VERSION}}".minfo
121
+ puts "Bindirs: {#{bindirs.join("}, {")}}".minfo
122
+ puts "Executables: {#{tbj_executables.length}}".minfo
123
+ puts "Executables path: {#{exepath}}".minfo
124
+ puts ""
125
+ puts "GitHub: {https://github.com/sevenc-nanashi/no_tbj}".minfo
126
+ puts "Copyright (c) 2021 {sevenc-nanashi}.".info
127
+ end
128
+
129
+ def add_bundler_script
130
+ bundler_ruby = <<~RUBY
131
+ #!/usr/bin/env ruby
132
+ #
133
+ # This file was generated by RubyGems.
134
+ #
135
+ # The application 'bundler' is installed as part of a gem, and
136
+ # this file is here to facilitate running it.
137
+ #
138
+
139
+ require 'rubygems'
140
+
141
+ version = ">= 0.a"
142
+
143
+ str = ARGV.first
144
+ if str
145
+ str = str.b[/\A_(.*)_\z/, 1]
146
+ if str and Gem::Version.correct?(str)
147
+ version = str
148
+ ARGV.shift
149
+ end
150
+ end
151
+
152
+ if Gem.respond_to?(:activate_bin_path)
153
+ load Gem.activate_bin_path('bundler', '!name!', version)
154
+ else
155
+ gem "bundler", version
156
+ load Gem.bin_path("bundler", "!name!", version)
157
+ end
158
+ RUBY
159
+ File.write(File.join(RbConfig::CONFIG["bindir"], "bundler"), bundler_ruby.sub("!name!", "bundler"))
160
+ File.write(File.join(RbConfig::CONFIG["bindir"], "bundle"), bundler_ruby.sub("!name!", "bundle"))
161
+ end
162
+
163
+ private
164
+
165
+ def tbj_executables
166
+ res = []
167
+ bindirs.each do |bindir|
168
+ res += Dir.glob(File.join(bindir, "*.exe")).filter do |file|
169
+ next if File.directory?(file)
170
+ File.open(file, "rb") do |f|
171
+ f.seek(-CHECKS.length, IO::SEEK_END)
172
+ f.read(CHECKS.length) == CHECKS
173
+ end
174
+ end
175
+ end
176
+ res
177
+ end
178
+
179
+ def exepath
180
+ File.join(__dir__, "runner.exe")
181
+ end
182
+
183
+ def exepath_gemlib
184
+ File.join(__dir__, "runner_gemlib.exe")
185
+ end
186
+
187
+ def bindirs
188
+ [RbConfig::CONFIG["bindir"], RbConfig::CONFIG["libdir"] + "/ruby/gems/" + RbConfig::CONFIG["ruby_version"] + "/bin"]
189
+ end
190
+ end
191
+ end
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NoTBJ
4
+ VERSION = "0.1.0"
5
+ end
data/lib/no_tbj.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "no_tbj/version"
4
+ require_relative "no_tbj/core"
5
+
6
+ module NoTBJ
7
+ class Error < StandardError; end
8
+
9
+ # Your code goes here...
10
+ end
data/no_tbj.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/no_tbj/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "no_tbj"
7
+ spec.version = NoTBJ::VERSION
8
+ spec.authors = ["sevenc-nanashi"]
9
+ spec.email = ["sevenc-nanashi@sevenbot.jp"]
10
+
11
+ spec.summary = "No more Terminate Batch Job!"
12
+ spec.description = "This gem deletes 'Terminate Batch Job (Y/N)' dialog."
13
+ spec.homepage = "https://github.com/sevenc-nanashi/no_tbj"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/sevenc-nanashi/no_tbj"
19
+ spec.metadata["changelog_uri"] = "https://github.com/sevenc-nanashi/no_tbj/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.files << "lib/no_tbj/runner.exe"
27
+ spec.files << "lib/no_tbj/runner_gemlib.exe"
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: no_tbj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sevenc-nanashi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem deletes 'Terminate Batch Job (Y/N)' dialog.
14
+ email:
15
+ - sevenc-nanashi@sevenbot.jp
16
+ executables:
17
+ - no_tbj
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - exe/no_tbj
31
+ - go/runner.go
32
+ - go/runner_gemlib.go
33
+ - lib/no_tbj.rb
34
+ - lib/no_tbj/color.rb
35
+ - lib/no_tbj/core.rb
36
+ - lib/no_tbj/runner.exe
37
+ - lib/no_tbj/runner_gemlib.exe
38
+ - lib/no_tbj/version.rb
39
+ - no_tbj.gemspec
40
+ homepage: https://github.com/sevenc-nanashi/no_tbj
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: https://github.com/sevenc-nanashi/no_tbj
45
+ source_code_uri: https://github.com/sevenc-nanashi/no_tbj
46
+ changelog_uri: https://github.com/sevenc-nanashi/no_tbj/blob/main/CHANGELOG.md
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.0.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.2.22
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: No more Terminate Batch Job!
66
+ test_files: []