un 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/lib/un.rb +49 -4
  4. data/un.gemspec +2 -2
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 570bbaaa3fd83fed605b117c23c1a1b6a8ca94579bdbfa716f1116186c80b8be
4
- data.tar.gz: 5a4b7ebda1ce0472dcfe36cc0901849382d1c3e9e9a39023e6413e5022cadc6f
3
+ metadata.gz: d8c8d915490e45125d7b38a47b0aeb67b28b9ab530c7fba21839a05f8343e34d
4
+ data.tar.gz: 7017890ba253218048086124b79a493885bcc6bc6441023faf1a58ec82e32075
5
5
  SHA512:
6
- metadata.gz: ef5c05b6d7b732d21b2892f6e962db79b028353da5631f5be8b5e4515a491a73b3f9c3aae7bd4fd73b1909eaf8ef5ad4640203a246dedf5be4904837dc61d314
7
- data.tar.gz: c31d629139e8714c81fc000d286c387d93910a8f6ee69c360703ed9ed79ddd6889583527bd51cda392c6e08841970ff82f0697f3fbd64be4e2411641da53d501
6
+ metadata.gz: f579ec63b6cbc2c69a29df7b4d90c897b44384a807f13714895f7505696dbe742aee8825602010e3a0aefe1a4a53cad5b2480c4e31d43c2081ea6425d1262e3f
7
+ data.tar.gz: efd61b8e25c638735bd9349eec4098ab0d5aed956b1ec6ca5fa9847a63ac9fc6625f97bc661d1d44b2ab546362c759514caa3dde6ea227cb461ccb284b7d512e
data/README.md CHANGED
@@ -33,6 +33,7 @@ ruby -run -e touch -- [OPTION] FILE
33
33
  ruby -run -e wait_writable -- [OPTION] FILE
34
34
  ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
35
35
  ruby -run -e httpd -- [OPTION] [DocumentRoot]
36
+ ruby -run -e colorize -- [FILE]
36
37
  ruby -run -e help [COMMAND]
37
38
  ```
38
39
 
data/lib/un.rb CHANGED
@@ -23,6 +23,7 @@
23
23
  # ruby -run -e wait_writable -- [OPTION] FILE
24
24
  # ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
25
25
  # ruby -run -e httpd -- [OPTION] [DocumentRoot]
26
+ # ruby -run -e colorize -- [FILE]
26
27
  # ruby -run -e help [COMMAND]
27
28
 
28
29
  require "fileutils"
@@ -78,13 +79,15 @@ end
78
79
  #
79
80
  # -p preserve file attributes if possible
80
81
  # -r copy recursively
82
+ # -l make hard link instead of copying (implies -r)
81
83
  # -v verbose
82
84
  #
83
85
 
84
86
  def cp
85
- setup("pr") do |argv, options|
87
+ setup("prl") do |argv, options|
86
88
  cmd = "cp"
87
89
  cmd += "_r" if options.delete :r
90
+ cmd = "cp_lr" if options.delete :l
88
91
  options[:preserve] = true if options.delete :p
89
92
  dest = argv.pop
90
93
  argv = argv[0] if argv.size == 1
@@ -253,7 +256,7 @@ def wait_writable
253
256
  wait = (wait = options[:w]) ? Float(wait) : 0.2
254
257
  argv.each do |file|
255
258
  begin
256
- open(file, "r+b")
259
+ File.open(file, "r+b") {}
257
260
  rescue Errno::ENOENT
258
261
  break
259
262
  rescue Errno::EACCES => e
@@ -326,7 +329,11 @@ def httpd
326
329
  "ServerName=NAME", "ServerSoftware=NAME",
327
330
  "SSLCertificate=CERT", "SSLPrivateKey=KEY") do
328
331
  |argv, options|
329
- require 'webrick'
332
+ begin
333
+ require 'webrick'
334
+ rescue LoadError
335
+ abort "webrick is not found. You may need to `gem install webrick` to install webrick."
336
+ end
330
337
  opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
331
338
  [:Port, :MaxClients].each do |name|
332
339
  opt = options[name] and (options[name] = Integer(opt)) rescue nil
@@ -342,6 +349,21 @@ def httpd
342
349
  end
343
350
  options[:Port] ||= 8080 # HTTP Alternate
344
351
  options[:DocumentRoot] = argv.shift || '.'
352
+ s = nil
353
+ options[:StartCallback] = proc {
354
+ logger = s.logger
355
+ logger.info("To access this server, open this URL in a browser:")
356
+ s.listeners.each do |listener|
357
+ if options[:SSLEnable]
358
+ addr = listener.addr
359
+ addr[3] = "127.0.0.1" if addr[3] == "0.0.0.0"
360
+ addr[3] = "::1" if addr[3] == "::"
361
+ logger.info(" https://#{Addrinfo.new(addr).inspect_sockaddr}")
362
+ else
363
+ logger.info(" http://#{listener.connect_address.inspect_sockaddr}")
364
+ end
365
+ end
366
+ }
345
367
  s = WEBrick::HTTPServer.new(options)
346
368
  shut = proc {s.shutdown}
347
369
  siglist = %w"TERM QUIT"
@@ -354,6 +376,29 @@ def httpd
354
376
  end
355
377
  end
356
378
 
379
+ ##
380
+ # Colorize ruby code.
381
+ #
382
+ # ruby -run -e colorize -- [FILE]
383
+ #
384
+
385
+ def colorize
386
+ begin
387
+ require "irb/color"
388
+ rescue LoadError
389
+ raise "colorize requires irb 1.1.0 or later"
390
+ end
391
+ setup do |argv, |
392
+ if argv.empty?
393
+ puts IRB::Color.colorize_code STDIN.read
394
+ return
395
+ end
396
+ argv.each do |file|
397
+ puts IRB::Color.colorize_code File.read(file)
398
+ end
399
+ end
400
+ end
401
+
357
402
  ##
358
403
  # Display help message.
359
404
  #
@@ -377,7 +422,7 @@ module UN # :nodoc:
377
422
  messages = {}
378
423
  store = proc {|msg| messages[cmd] = msg}
379
424
  end
380
- open(__FILE__) do |me|
425
+ File.open(__FILE__) do |me|
381
426
  while me.gets("##\n")
382
427
  if help = me.gets("\n\n")
383
428
  if all or argv.include?(cmd = help[/^#\s*ruby\s.*-e\s+(\w+)/, 1])
data/un.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "un"
5
- spec.version = "0.1.0"
5
+ spec.version = "0.2.1"
6
6
  spec.authors = ["WATANABE Hirofumi"]
7
7
  spec.email = ["eban@ruby-lang.org"]
8
8
 
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
20
20
  end
21
21
  spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
+ spec.executables = []
23
23
  spec.require_paths = ["lib"]
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: un
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WATANABE Hirofumi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-03 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Utilities to replace common UNIX commands
14
14
  email:
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.0.rc.2
51
+ rubygems_version: 3.4.0.dev
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: Utilities to replace common UNIX commands