-
Notifications
You must be signed in to change notification settings - Fork 1
/
init
executable file
·49 lines (37 loc) · 1.22 KB
/
init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
# frozen_string_literal: true
mydir = File.dirname(File.expand_path($PROGRAM_NAME))
skip = ['.', '..', '.git', '.gitignore', '.gitmodules', '.travis.yml', 'init',
'README', 'config']
myhome = ENV['HOME']
Dir.entries(mydir).each do |entry|
next if skip.member? entry
src = File.join(mydir, entry)
next if entry =~ /^_/
dst = File.join(myhome, entry.insert(0, '.'))
if File.symlink?(dst) || !File.exist?(dst)
File.unlink dst if File.exist? dst
File.symlink(src, dst)
puts "#{src} -> #{dst}"
else
puts "refusing to touch #{dst}, not a symlink"
end
end
# link files in config/ to ~/.config/
config_src_dir = File.join(mydir, 'config')
config_dst_dir = File.join(myhome, '.config')
Dir.entries(config_src_dir).each do |entry|
next if ['.', '..'].member? entry
src = File.join(config_src_dir, entry)
dst = File.join(config_dst_dir, entry)
if File.symlink?(dst) || !File.exist?(dst)
File.unlink dst if File.exist? dst
File.symlink(src, dst)
puts "#{src} -> #{dst}"
else
puts "refusing to touch #{dst}, not a symlink"
end
end
dshort = File.join(myhome, '.dotfiles')
File.symlink mydir, dshort unless File.exist? dshort
# vim: set ft=ruby et ts=2 sw=2 tw=79: