forked from TheodorRene/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocaf
executable file
·131 lines (111 loc) · 2.79 KB
/
rocaf
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/ruby
file = ARGV[0]
if ["--help", "-h"].include? file
puts %{
rocaf [OPTIONS] [FILE]
-------------------------------------------------------------
"Run Or Compile Any File"
Takes in one(1) file as argument
Returns output from running the file given the file extension
-------------------------------------------------------------
Supported extensions are md(markdown), py(python), rb(ruby) and tex(latex).
Simple support for cpp(C++) and hs(Haskell)
}
exit(0)
end
if file.nil?
puts %{
No file given. rocaf -h for help
}
exit(0)
end
ending = file.match(/.*\.(.*$)/)
## Functions for executing programs ##
comp_markdown = proc {|file|
nameOfFile = file.match(/(.*)\.(.*$)/)
if !nameOfFile.nil?
shell_cmd = `pandoc #{file} --pdf-engine=xelatex -o #{nameOfFile[1]}.pdf`
puts shell_cmd
`notify-send -t 1000 "#{file} compiled to pdf"`
puts "Markdown file parsed"
else
puts "Something went wrong"
end
}
run_python = proc { |file|
puts `python3 #{file}`
}
run_ruby = proc { |file|
puts `ruby #{file}`
}
run_bash = proc{ |file|
puts `bash #{file}`
}
comp_latex = proc { |file|
puts `latexmk -pdf #{file}`
}
run_cpp_old = proc { |file|
no_suffix = file.delete_suffix('.cpp')
puts `g++ -std=c++0x -o #{no_suffix} #{file} && ./#{no_suffix}`
}
run_cpp = proc { |file|
no_suffix = file.delete_suffix('.cpp')
puts `make && ./#{no_suffix}`
}
run_c = proc { |file|
no_suffix = file.delete_suffix('.c')
#puts `gcc -fsanitize=address -g -o0 -Wall -o #{no_suffix} #{file} && ./#{no_suffix}`
puts `gcc -g -o0 -Wall -o #{no_suffix} #{file} && ./#{no_suffix}`
}
run_haskell = proc { |file|
no_suffix = file.delete_suffix('.hs')
puts `ghc -o #{no_suffix} #{file} && ./#{no_suffix}`
}
run_rust_old = proc { |file|
puts `rustc #{file} && ./#{file.delete_suffix('.rs')}`
}
run_rust = proc { |file|
puts `cargo run`
}
run_js = proc { |file|
puts `node #{file}`
}
run_ts = proc { |file|
puts `npx ts-node #{file}`
}
run_java = proc { |file|
puts `gradle run`
}
comp_dot = proc { |file|
puts `dot -Tpng #{file} > #{file.delete_suffix('.dot')}.png`
}
## End ##
## Hash with possible file extensions mapped to executing programs ##
func_hash = {'md' => comp_markdown,
'c' => run_c,
'cpp' => run_cpp,
'dot' => comp_dot,
'hs' => run_haskell,
'java' => run_java,
'py' => run_python,
'rb' => run_ruby,
'rs' => run_rust,
'sh' => run_bash,
'tex' => comp_latex,
'js' => run_js,
'ts' => run_ts
}
## End ##
# MAIN #
if !ending.nil?
begin
func_hash.fetch(ending[1]).call(file)
exit(0)
rescue KeyError
puts "File ending not supported"
exit(1)
end
else
puts "No file ending found"
exit(1)
end