dorian-dot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/dot +4 -0
  3. data/lib/dorian/dot.rb +40 -0
  4. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac91a7d5e0c81ef488f219e5924a6840fc1859e4a2c161a42a680f07397ac516
4
+ data.tar.gz: 13feae4513932ff8f68e5941ee8807427755714cb6a18112ffa473a41890c4e0
5
+ SHA512:
6
+ metadata.gz: 6bc8a021e14e7780450d34c042c36e08ec1b6802871201c161ee1c97ebd2e87eb7bffa66b65310a13ccc362e02bb7edf7589967cb450ada47063c5965630aae9
7
+ data.tar.gz: ecc9cb6a2d7ce874c50e93ca8af854c967218df6781bbdaa9e3b510d616a61d067bcf605dc8e4df5382863d7f904d5640ba016706bb13605a83ec2735d59b7fa
data/bin/dot ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dorian/dot'
4
+ Dorian::Dot.run
data/lib/dorian/dot.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "fileutils"
2
+
3
+ module Dorian
4
+ class Dot
5
+ def self.run
6
+ if ARGV.size < 1 || ARGV.size > 2 || ARGV[0] == "--help" || ARGV[0] == "-h"
7
+ puts "USAGE: dot DIRECTORY [--confirm]"
8
+ exit
9
+ end
10
+
11
+ dir = ARGV[0]
12
+ confirm = ARGV[1] == "--confirm"
13
+ files = Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH)
14
+ files = files.grep_v(/\/.git\//).grep_v(/\/\.$/).grep_v(/\/\.\.$/)
15
+ files = files.select { |file| File.file?(file) }
16
+ files.each do |file|
17
+ file = file.gsub("//", "/")
18
+ barefile = file.gsub(dir, "").gsub(/^\//, "")
19
+ homefile = "#{Dir.home}/#{barefile}".gsub("//", "/")
20
+
21
+ if File.exists?(homefile)
22
+ if confirm
23
+ FileUtils.rm(homefile)
24
+ else
25
+ print "#{homefile} file exists, delete? (y/N) "
26
+ answer = confirm ? "yes" : $stdin.gets.strip
27
+
28
+ if answer[0].to_s.downcase == "y"
29
+ FileUtils.rm(homefile)
30
+ else
31
+ exit
32
+ end
33
+ end
34
+ end
35
+
36
+ FileUtils.ln_s(file, homefile, verbose: true)
37
+ end
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dorian-dot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dorian Marié
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Links dot files
15
+
16
+ e.g. `dot src/clones/dotfiles`
17
+ email: dorian@dorianmarie.fr
18
+ executables:
19
+ - dot
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/dot
24
+ - lib/dorian/dot.rb
25
+ homepage: https://github.com/dorianmariefr/dot
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.2.22
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Links dot files
49
+ test_files: []