-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetar.rb
More file actions
executable file
·32 lines (28 loc) · 816 Bytes
/
etar.rb
File metadata and controls
executable file
·32 lines (28 loc) · 816 Bytes
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
#!/usr/bin/ruby
IGNORES= [/\.{1,2}$/ , /\A\.git$/, /\A.+\.e?tar$/]
IGNORES << /^\./ # ignore hidden files
def etar(paths)
paths = Array(paths)
paths.each do |path|
Dir.entries(path).each do |entry|
fullname = File.join(path, entry)
next if IGNORES.inject(false) { |v, ig| v || entry =~ ig }
case
when File.symlink?(fullname)
next
when File.directory?(fullname)
etar(fullname)
when File.file?(fullname)
key = "__END_OF_#{entry}__"
puts "filename='#{fullname}'"
puts "mkdir -p \$(dirname $filename)"
puts "cat <<#{key} > $filename"
File.open(fullname).each_line do |line|
puts line.gsub(/([$\\`])/, '\\\\\1')
end
puts "#{key}"
end
end
end
end
etar(ARGV.size>0 ? ARGV : '.')