-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitkeepDir.rb
executable file
·56 lines (42 loc) · 959 Bytes
/
GitkeepDir.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
#!/usr/bin/ruby
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def red(text)
colorize(text, 31)
end
def green(text)
colorize(text, 32)
end
class String
def liste_rep(path = "")
liste_exclus = [".", "..", ".git"]
dir = Dir.open(self)
liste_dir = dir.sort - liste_exclus
if (liste_dir.size == 0)
puts path + "/.gitkeep " + green('Added')
fd = File.new(path + "/.gitkeep", "w+")
fd.close
end
if (liste_dir.size > 1 && liste_dir.index(".gitkeep") != nil)
puts path + "/.gitkeep " + red('Removed')
File.delete(path + "/.gitkeep")
end
liste_dir.each { |fichier|
path = self + fichier
if (fichier != ".gitkeep")
case File.ftype(path)
when "directory"
(path + "/").liste_rep(path)
end
end
}
end
end
if (ARGV.size == 0)
"./".liste_rep()
else
ARGV.each do|arg|
"./".liste_rep(arg)
end
end