-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_tools_homey
executable file
·77 lines (61 loc) · 1.72 KB
/
s_tools_homey
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env ruby
#
# Bin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bin. If not, see <https://www.gnu.org/licenses/>.
#
# frozen_string_literal: true
# Symlink partition folders to $HOME
class Homey
IGNORE_THESE = %w[.Trash-1000 lost+found].freeze
attr_reader :root, :target_link
def initialize(root)
@root = root
end
# Confirms if root is a folder or return w/ exeception
def root_exist?
Pathname.new root.exist?
end
def folders_found
folders_found = {}
home = Pathname.new Dir.home
root.each_child do |folder|
next if IGNORE_THESE.include? folder.basename.to_s
folders_found[folder] = home.join folder.basename
end
folders_found
end
# Remove $HOME folders found in partition
def cleanup_home
target_link.each_key do |link_name|
link_name.delete if link_name.exist?
end
end
def symlink_folders
target_link.each do |target, link_name|
File.symlink target, link_name
end
end
def run
unless root_exist?
print "No such a directory '#{root}' exist! Exiting."
exit!
end
@root = Pathname root
@target_link = folders_found
cleanup_home
symlink_folders
end
public :run
end
# RUN
Homey.new(ARGV.first).run