-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRakefile
More file actions
69 lines (55 loc) · 1.68 KB
/
Rakefile
File metadata and controls
69 lines (55 loc) · 1.68 KB
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
HOME = File.expand_path('~')
BASH_COMPLETION_DIR = File.join(HOME, '.bash_completion.d/')
COMPLETION_SCRIPTS = Dir['bash_completion.d/*']
DOT_FILES = Dir['dot_files/*']
FORCE = ENV.include?("force") && (ENV["force"]=='true'||ENV["force"]=="1") ? true : false
desc "Install the package"
task :install do
puts "INSTALLING"
puts "================================================================"
check_bash_completion_dir
DOT_FILES.each do |file|
target = File.join(HOME, ".#{File.basename(file)}")
check_and_install(file, target)
end
COMPLETION_SCRIPTS.each do |file|
target = File.join(BASH_COMPLETION_DIR, File.basename(file))
check_and_install(file, target)
end
puts """
================================================================
Installation completed.
Please make sure to edit your #{File.join(HOME,".bashrc")} and add the following snippet:
# My custom bash completions
if [ -f ~/.bash_completion ]; then
. ~/.bash_completion
fi
Then load your scripts:
. #{File.join(HOME,".bashrc")}
"""
end
def check_and_install(file, target)
if File.exist?(target)
file_exists = "File #{target} exists. "
if FORCE == true
puts file_exists << "Unlinking."
File.unlink(target)
link_file(file, target)
else
puts file_exists << "Use rake install force=true to override."
end
else
link_file(file, target)
end
puts ""
end
def link_file(file, target)
`ln -nis #{File.expand_path file} #{target}`
puts "Installed #{file} in #{target}"
end
def check_bash_completion_dir
unless File.exist?(BASH_COMPLETION_DIR)
puts "Creating directory in #{BASH_COMPLETION_DIR}"
Dir.mkdir(BASH_COMPLETION_DIR)
end
end