hiiro 0.1.169 → 0.1.170

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9a90de4bbf5f17d90890078b14a3b5ce6eccd4aed9a7c4a7c7b5fc3b7da4f97
4
- data.tar.gz: 43f9ef18fd88cfdc7a1535dad5c88c6df56c264ff2fcd659d79e0180730e52b7
3
+ metadata.gz: 72a0ad30e0ada0bea531d4a2d9f0724b1e82f2f3f785c44dda3fbad2d28abb61
4
+ data.tar.gz: 3f2e11e363408038c0910b1f66d5d7240c15510c85d04599fc973a2c4a9ae203
5
5
  SHA512:
6
- metadata.gz: c69d5f1c2a0eacad95e7e8aefd985c31bcbf8ddc3ab29357806706d5da52dc207eeab9010535d1d8aa9191b485d6dc96a7bc81ac4af416e76d50150e5e9fd441
7
- data.tar.gz: 0fb174d064742171d5592a79c554582856989b6bbfcba5631ddcf7f8526a8789bd26a1a5b1bffab01d53804cb082319935583a475b43661fc155c06bad60ed17
6
+ metadata.gz: d7da2d57be1be7c956e9221ed3f16e96cad9e6793eba5f7f2aadaffb097c2678c13f02f3346de33ac287daaff8436733328d4babe55fb566fda76133a961c28f
7
+ data.tar.gz: c5f99d312ed8baed31c2540182389b0cd59ff33cd0da0534473aa0e3d22a5ac6b3d06170f85f8523705e97fa0abdc6a5f9b4cbf144a719c771e49f83d69cfa3b
data/bin/h-misc CHANGED
@@ -6,11 +6,10 @@ require 'awesome_print'
6
6
  Hiiro.run {
7
7
  add_subcmd(:symlink_destinations) do |*args|
8
8
  opts = Hiiro::Options.parse(args) do
9
- option(:root, short: :r, desc: 'root path')
9
+ option(:root, short: :r, default: `git rev-parse --show-toplevel 2>/dev/null`.strip, desc: 'root path')
10
10
  end
11
11
 
12
- repo_root = Pathname.new(opts.root || git.root)
13
- pwd = Hiiro::Paths.new(Dir.pwd)
12
+ pwd = Hiiro::Paths.new(Dir.pwd, hiiro: this)
14
13
  outside = Hash.new { |h,k| h[k] = [] }
15
14
 
16
15
  opts.args.each_with_object(outside) do |basedir,h|
@@ -21,10 +20,9 @@ Hiiro.run {
21
20
 
22
21
  outside.each do |base, links|
23
22
  puts "# symlinks outside of => #{base}"
24
- dest_width = links.map{|l| l.dest_relative_to(repo_root).to_s.length }.max
23
+ dest_width = links.map{|l| l.dest_from_root.to_s.length }.max
25
24
  links.each do |link|
26
- rel_dest = link.dest_relative_to(repo_root)
27
- printf("%-*s # => %s\n", dest_width, rel_dest, link.path)
25
+ printf("%-*s # => %s\n", dest_width, link.dest_from_root, link.path)
28
26
  end
29
27
  end
30
28
  end
data/lib/hiiro/git.rb CHANGED
@@ -9,7 +9,7 @@ class Hiiro
9
9
  class Git
10
10
  attr_reader :hiiro, :pwd
11
11
 
12
- def initialize(hiiro, pwd)
12
+ def initialize(hiiro, pwd=Dir.pwd)
13
13
  @hiiro = hiiro
14
14
  @pwd = pwd
15
15
  end
data/lib/hiiro/paths.rb CHANGED
@@ -5,10 +5,11 @@ require "delegate"
5
5
 
6
6
  class Hiiro
7
7
  class Paths
8
- attr_reader :base
8
+ attr_reader :base, :hiiro
9
9
 
10
- def initialize(base=Dir.pwd)
10
+ def initialize(base=Dir.pwd, hiiro: nil)
11
11
  @base = Pathname.new base
12
+ @hiiro = hiiro
12
13
  end
13
14
 
14
15
  def from_base(file)
@@ -17,14 +18,21 @@ class Hiiro
17
18
  end
18
19
 
19
20
  def symlinks_in(path)
20
- subdir = Pathname.new(path)
21
+ subdir = Pathname.new(path).expand_path
21
22
 
22
23
  subdir.find
23
24
  .select(&:symlink?)
24
- .map { |link| Symlink.new(link) }
25
+ .map { |link| Symlink.new(link, hiiro) }
25
26
  end
26
27
 
27
28
  class Symlink < SimpleDelegator
29
+ attr_reader :hiiro
30
+
31
+ def initialize(path, hiiro=nil)
32
+ @hiiro = hiiro
33
+ super(path)
34
+ end
35
+
28
36
  def path
29
37
  @path ||= Pathname.new(__getobj__)
30
38
  end
@@ -33,9 +41,24 @@ class Hiiro
33
41
  path.readlink
34
42
  end
35
43
 
36
- def dest_relative_to(root)
37
- abs = (path.dirname + dest).cleanpath
38
- abs.relative_path_from(Pathname.new(root))
44
+ def root
45
+ @root ||= hiiro&.git&.root || `git rev-parse --show-toplevel 2>/dev/null`.chomp
46
+ end
47
+
48
+ def root_path
49
+ Pathname.new root
50
+ end
51
+
52
+ def abs_dest
53
+ (path.dirname + dest).cleanpath
54
+ end
55
+
56
+ def dest_from_root
57
+ abs_dest.relative_path_from(root_path)
58
+ end
59
+
60
+ def dest_relative_to(base_dir)
61
+ abs_dest.relative_path_from(Pathname.new(base_dir))
39
62
  end
40
63
 
41
64
  def dest_dir
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.169"
2
+ VERSION = "0.1.170"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.169
4
+ version: 0.1.170
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota