dit 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/dit +4 -0
- data/lib/dit.rb +173 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74c6480d2fc0399121019b398353cea7868f8005
|
4
|
+
data.tar.gz: f541e05d5e8c8f49d94e41a672579eb2c7ce4764
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 389cada647157c1d25eb241c29c24c5bdb4192ad44a50cb7046402fc7420d884413652e1afb5916d781b05b05b85b4493dbc894089fceccf1f5443f8e5b16744
|
7
|
+
data.tar.gz: 78329737e0e2933c4af3e2f9675e540c9bd17075d320458fa1842dd291702d016b10e194ddc7ae534e4834cd726e9e2ff634f602c65b1713e7eb1502fee675fd
|
data/bin/dit
ADDED
data/lib/dit.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'git'
|
3
|
+
require 'os'
|
4
|
+
require 'json'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
class Dit
|
8
|
+
def self.init
|
9
|
+
if(Dir.exist?(".dit"))
|
10
|
+
puts "This is already a dit repo, so all we have to do is symlink to home."
|
11
|
+
symlink_all
|
12
|
+
hook
|
13
|
+
return
|
14
|
+
elsif(Dir.exist?(".git"))
|
15
|
+
repo = Git.open(Dir.getwd)
|
16
|
+
else
|
17
|
+
repo = Git.init(Dir.getwd)
|
18
|
+
puts "Initialized empty Git repository in #{File.join(Dir.getwd, ".git")}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Make a .dit dir and a settings hash to be exported to a file in dit dir
|
22
|
+
Dir.mkdir(".dit")
|
23
|
+
settings = {}
|
24
|
+
|
25
|
+
# create a .gitignore to ignore the os_dotfiles dir
|
26
|
+
File.open(".gitignore", "a") do |f|
|
27
|
+
f.write ".dit/os_dotfiles/"
|
28
|
+
f.write "\n"
|
29
|
+
f.write ".dit/local_settings.json"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Write our changes to a JSON file in the dit dir
|
33
|
+
File.open(File.join(".dit", "settings.json"), "a") do |f|
|
34
|
+
f.write settings.to_json if settings
|
35
|
+
end
|
36
|
+
|
37
|
+
repo.add(".dit/settings.json")
|
38
|
+
repo.add(".gitignore")
|
39
|
+
repo.commit("Dit inital commit")
|
40
|
+
|
41
|
+
clone_os_dotfiles
|
42
|
+
hook
|
43
|
+
|
44
|
+
puts "Initialized empty Dit repository in #{File.join(Dir.getwd, ".dit")})"
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.hook
|
48
|
+
return unless Dir.exist?(".dit")
|
49
|
+
Dir.chdir(File.join(".git", "hooks")) do
|
50
|
+
p Dir.getwd
|
51
|
+
FileUtils.rm_rf Dir.glob("*")
|
52
|
+
File.open(("post-commit"), "a") do |f|
|
53
|
+
f.write "#!/usr/bin/env ./.git/hooks/force-ruby\n"
|
54
|
+
f.write "require 'dit'\n"
|
55
|
+
f.write "Dit.symlink_unlinked\n"
|
56
|
+
end
|
57
|
+
File.open(("post-merge"), "a") do |f|
|
58
|
+
f.write "#!/usr/bin/env ./.git/hooks/force-ruby\n"
|
59
|
+
f.write "require 'dit'\n"
|
60
|
+
f.write "Dit.symlink_unlinked\n"
|
61
|
+
end
|
62
|
+
# The following lines are because git hooks do this weird thing
|
63
|
+
# where they prepend /usr/bin to the path and a bunch of other stuff
|
64
|
+
# meaning git hooks will use /usr/bin/ruby instead of any ruby
|
65
|
+
# from rbenv or rvm or chruby, so we make a script forcing the hook
|
66
|
+
# to use our ruby
|
67
|
+
ruby_path = `which ruby`
|
68
|
+
if(ruby_path != "/usr/bin/ruby")
|
69
|
+
ruby_folder = File.dirname(ruby_path)
|
70
|
+
File.open(("force-ruby"), "a") do |f|
|
71
|
+
f.write "#!/usr/bin/env bash\n"
|
72
|
+
f.write "set -e\n"
|
73
|
+
if ENV['RBENV_ROOT']
|
74
|
+
# Use Rbenv's shims
|
75
|
+
# By the way, if anyone has particular PATHs I should use for
|
76
|
+
# RVM or chruby, please let me know!
|
77
|
+
f.write "PATH=#{File.join(ENV['RBENV_ROOT'], "shims")}:$PATH\n"
|
78
|
+
else
|
79
|
+
f.write "PATH=#{ruby_folder}:$PATH\n"
|
80
|
+
end
|
81
|
+
f.write "exec ruby \"$@\"\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
FileUtils.chmod '+x', %w(post-commit post-merge force-ruby)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.clone_os_dotfiles
|
90
|
+
# OS Specific Dotfiles Eventually TM
|
91
|
+
file_url = "file:///" + File.absolute_path(Dir.getwd)
|
92
|
+
Dir.chdir(".dit") do
|
93
|
+
os_dotfiles = Git.clone(file_url, "os_dotfiles")
|
94
|
+
os_dotfiles.branch("master").checkout
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.symlink_all
|
99
|
+
Dir.chdir(File.join(repo_name, ".dit", "os_dotfiles")) do
|
100
|
+
Find.find('.') do |d|
|
101
|
+
if File.directory?(d)
|
102
|
+
Dir.mkdir(File.join(Dir.home, d.split['os_dotfiles'][1]))
|
103
|
+
Dir.entries(d).each do |f|
|
104
|
+
next if (f === '.' || f === '..')
|
105
|
+
abs_f = File.absolute_path(f)
|
106
|
+
rel_f = File.join(Dir.home, abs_f.split("os_dotfiles")[1])
|
107
|
+
File.symlink(abs_f, rel_f) unless File.exists?(rel_f)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.symlink_unlinked
|
115
|
+
settings = nil
|
116
|
+
begin
|
117
|
+
settings = JSON.parse File.open(
|
118
|
+
File.join(Dir.getwd, ".dit", "local_settings.json"), "r").read.close
|
119
|
+
rescue
|
120
|
+
settings = {
|
121
|
+
symlinked: []
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
Dir.chdir(".dit") do
|
126
|
+
Dir.chdir("os_dotfiles") do
|
127
|
+
Git.open(Dir.getwd).pull
|
128
|
+
os_changed_files = `git show --pretty="format:" --name-only HEAD`
|
129
|
+
os_changed_files.split('\n').each do |file|
|
130
|
+
file.strip! # strip newlines
|
131
|
+
next if os_list.include?(file.split('.').pop())
|
132
|
+
next if settings[:symlinked].include?(file)
|
133
|
+
next if file.include?(".dit")
|
134
|
+
File.symlink(
|
135
|
+
File.absolute_path(file),
|
136
|
+
File.absolute_path(File.join(Dir.home, file)))
|
137
|
+
settings[:symlinked] << file
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
File.open(File.join(Dir.getwd, ".dit", "local_settings.json"), "w+") do |f|
|
143
|
+
f.truncate 0
|
144
|
+
f.write settings.to_json
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def self.repo
|
151
|
+
Git.open(Dir.getwd)
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.os_list
|
155
|
+
[
|
156
|
+
'windows',
|
157
|
+
'osx',
|
158
|
+
'arch',
|
159
|
+
'fedora',
|
160
|
+
'debian',
|
161
|
+
'ubuntu',
|
162
|
+
'slack',
|
163
|
+
'bsd'
|
164
|
+
]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class DitCMD < Thor
|
169
|
+
desc "init", "Initialize the current directory as a dit directory."
|
170
|
+
def init
|
171
|
+
Dit.init
|
172
|
+
end
|
173
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Fahringer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: git
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.2.9
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.2.9
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: os
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.6
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.9.6
|
61
|
+
description: Dit is a dotfiles manager that wraps around git and makes dotfiles easy
|
62
|
+
to manage across devices.
|
63
|
+
email: hispanic@hush.ai
|
64
|
+
executables:
|
65
|
+
- dit
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- bin/dit
|
70
|
+
- lib/dit.rb
|
71
|
+
homepage: http://github.com/vulpino/dit
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.4.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Dit is a dotfiles manager that thinks it's git.
|
95
|
+
test_files: []
|
96
|
+
has_rdoc:
|