forked from caldwell/build-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverbose-shell.rb
68 lines (55 loc) · 1.55 KB
/
verbose-shell.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'fileutils'
class VerboseShell
@@verbose = nil
def self.verbose; @@verbose; end
def self.verbose=(v); @@verbose = v; end
def self.system_trace(*args)
return unless @@verbose
puts "+ "+args.map{|a| a =~ /\s/ ? '"'+a+'"' : a}.join(' ')
end
def self.system(*args)
system_trace *args
Kernel.system *args or abort "#{args[0]} failed"
end
def self.systemr(*args)
system_trace *args
Kernel.system *args
end
def self.capture(*args)
system_trace *args
IO.popen(args + (@verbose == 0 ? [{:err => "/dev/null"}] : []), "r") {|io| io.read}.strip
end
def self.mv(src,dest,options={})
system_trace *%W"mv #{src} #{dest}"
FileUtils.mv(src, dest, options)
end
def self.chmod(mode,list,options={})
list = [list] unless list.class == Array
system_trace *%W"chmod #{mode} "+list
FileUtils.chmod(mode, list, options)
end
def self.cp(src,dest,options={})
system_trace *%W"cp #{src} #{dest}"
FileUtils.cp(src, dest, options)
end
def self.cp_r(src,dest,options={})
system_trace *%W"cp -r #{src} #{dest}"
FileUtils.cp_r(src, dest, options)
end
def self.ln_s(src,dest,options={})
system_trace *%W"ln -s #{src} #{dest}"
FileUtils.ln_s(src, dest, options)
end
def self.rm_rf(file,options={})
system_trace *%W"rm -rf #{file}"
FileUtils.rm_rf file, options
end
def self.mkdir_p(file,options={})
system_trace *%W"mkdir -p #{file}"
FileUtils.mkdir_p file, options
end
def self.chdir(dir)
system_trace *%W"chdir #{dir}"
Dir.chdir dir
end
end