./src/src/functions.cr in politics-1.0.81 vs ./src/src/functions.cr in politics-1.0.82
- old
+ new
@@ -1,12 +1,27 @@
#!/usr/bin/crystal
-require "file_utils"
-require "json"
-require "colorize"
-include FileUtils
+def delete(arg)
+ `find -name #{arg}`.each_line do |i|
+ File.delete(i)
+ end
+end
+
+def nth_word(arg)
+ i = arg.to_u64 - 1
+ STDIN.each_line do |line|
+ puts line.split[i] rescue ""
+ end
+end
+
+def trim()
+ STDIN.each_line do |line|
+ puts line.strip
+ end
+end
+
def lines()
if !STDIN.tty?
puts STDIN.gets_to_end.count("\n")
else
res = `find .`.count("\n") - 1
@@ -46,18 +61,10 @@
p.wait
end
end
end
-def copy()
- command = "/usr/bin/xclip"
- args = ["-selection", "c"]
- Process.run(command, args, output: STDOUT) do |file|
- file.input.print STDIN.gets_to_end
- end
-end
-
def mul()
t = STDIN.read_line.to_f64
i = 0f64; STDIN.each_line do |line|
t *= line.to_f64
@@ -105,18 +112,10 @@
l = l.to_f64.abs
puts l
end
end
-def dump()
- puts STDIN.gets_to_end.dump
-end
-
-def undump()
- puts JSON.parse(STDIN.gets_to_end)
-end
-
def exp()
t = STDIN.read_line.to_f64
STDIN.each_line do |line|
t **= line.to_f64
@@ -136,14 +135,14 @@
end
end
def last_nth(arg1)
end_ = arg1.to_u64
- i = 0u64;
+ i = 0u64
t = STDIN.gets_to_end
if t[-1] == '\n'
- t = t[0..-2]
+ t = t[0..-2]
end
t.split("\n").reverse_each do |line|
i += 1
if i == end_
@@ -158,11 +157,11 @@
text = File.read(arg3).gsub(/#{arg1}/m, arg2)
File.open(t = File.tempname("coreutils", "_tmp"), "w", File.info(arg3).permissions) do |h|
h.print text
end
begin
- mv t, arg3
+ File.rename t, arg3
rescue
rm t
end
end
@@ -170,11 +169,11 @@
text = File.read(arg3).gsub(arg1, arg2)
File.open(t = File.tempname("coreutils", "_tmp"), "w", File.info(arg3).permissions) do |h|
h.print text
end
begin
- mv t, arg3
+ File.rename t, arg3
rescue
rm t
end
end
@@ -192,31 +191,30 @@
puts line
end
end
end
-
def swap(file1, file2)
[file1, file2].each do |f|
- File.exists?(f) || abort("No file named #{f.dump}".colorize(:red))
+ File.exists?(f) || abort("No file named #{f.dump}")
end
t = File.tempname("coreutils", "_tmp")
- mv file1, t
- mv file2, file1
- mv t, file2
+ File.rename file1, t
+ File.rename file2, file1
+ File.rename t, file2
end
def prepend(file)
file_data = File.read(file)
new_data = STDIN.gets_to_end
File.open(t = File.tempname("coreutils", "_tmp"), "w", File.info(file).permissions) do |h|
h << new_data + file_data
end
begin
- mv t, file
+ File.rename t, file
rescue
rm t
end
end
@@ -225,50 +223,36 @@
new_data = STDIN.gets_to_end
File.open(t = File.tempname("coreutils", "_tmp"), "w", File.info(file).permissions) do |h|
h << file_data + new_data
end
begin
- mv t, file
+ File.rename t, file
rescue
rm t
end
end
class Funcs
- def self.bold(text)
- text = text.to_s
- # text += two.to_s
-
- if STDOUT.tty?
- return text.colorize.bold.to_s
- else
- return "<b>" + text + "</b>"
- end
- end
-
def self.argument_data(program, usage, long_desc)
if !(STDOUT.tty?)
text = "<div style='border-radius: 50px; border: 10px dotted cyan; padding: 30px;'>\n"
else
text = ""
end
- text += bold("NAME") + "\n\t" + program
+ text += ("NAME") + "\n\t" + program
text += " - "
- text += program + "\n" * 2 + bold("SYNOPSIS") + "\n"
+ text += program + "\n" * 2 + ("SYNOPSIS") + "\n"
# tebold_("SYNOPSIS_")# + bold("SYNOPSIS")
text += "\t"
- text += bold(program) + " "
+ text += (program) + " "
text += usage + "\n\n"
text += long_desc + "\n\n"
if STDOUT.tty? == false
text = text.gsub("\n", "<br/> ").gsub("\t", " " * 5)
text += "</div>\n\n"
end
puts text
-
- # puts "</
- # puts "</
end
-end
\ No newline at end of file
+end