-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.rb
46 lines (41 loc) · 1.02 KB
/
profile.rb
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
class Profile
attr_reader :entries
def initialize
@entries = []
File.open(ENV['HOME'] + '/.ghoul_profile', 'a+') do |io|
while line = io.gets
if line.split.first == 'export'
@entries << Entry.new(line)
end
end
end
end
def write_profile
File.open(ENV['HOME'] + '/.ghoul_profile', 'w') do |io|
@entries.each do |e|
io.puts e.formatted
end
end
add_shim
end
private
def add_shim
shim_found = false
File.open(ENV['HOME'] + '/.profile', 'r') do |io|
while line = io.gets
if line.include? "[[ -s \"$HOME/.ghoul_profile\" ]] && source \"$HOME/.ghoul_profile\""
shim_found = true
end
end
end
unless shim_found
puts 'shim not found!!'
puts 'adding shim to ~/.profile'
File.open(ENV['HOME'] + '/.profile', 'a') do |io|
io << "\n"
io << "# Added by Ghoul\n"
io << "[[ -s \"$HOME/.ghoul_profile\" ]] && source \"$HOME/.ghoul_profile\""
end
end
end
end