-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexe
executable file
·91 lines (79 loc) · 2.03 KB
/
exe
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
#! /usr/bin/env zsh
lang=$1
if [ $lang = 'python' ]; then
extension=".py"
comment="#"
interpreter="python3"
compiler=""
init_code="\ndef main():\n\treturn\n\nif __name__ == '__main__':\n\tmain()"
elif [ $lang = 'julia' ]; then
extension=".jl"
comment="#"
interpreter="julia"
compiler=""
init_code=""
elif [ $lang = 'bash' ]; then
extension=".sh"
comment="#"
interpreter="bash"
compiler=""
init_code=""
elif [ $lang = 'zsh' ]; then
extension=".sh"
comment="#"
interpreter="zsh"
compiler=""
init_code=""
elif [ $lang = 'c' ]; then
extension=".c"
comment="//"
interpreter=""
compiler=$(gcc --version | head -n 1)
compiling="gcc -o $2.x $filename"
init_code="\nint main(){\n\treturn 0\n}"
elif [ $lang = 'cpp' ] || [ $lang = 'c++' ]; then
extension=".cpp"
comment="//"
interpreter=""
compiler=$(gcc --version | head -n 1)
compiling="gcc -lstdc++ -o $2.x $filename"
init_code="#include<iostream>\nusing namespace std;\n\nint main(){\n\treturn 0\n}"
elif [ $lang = 'fortran' ]; then
extension=".f90"
comment="!"
interpreter=""
compiler=$(gfortran --version | head -n 1)
compiling="gfortran -Wall -pedantic -std=f95 -c -o $2.out $2$extension && gfortran -o $2.x $2.out"
init_code="\nPROGRAM $2\n\n\nEND PROGRAM"
fi
printf "Use default file extension ($extension)? [Y/n] " >&2
read -r ans
if [[ "$ans" =~ ^([nN][oO]|[nN])$ ]]; then
filename=$2
else
filename="$2$extension"
fi
touch $filename
# Shbang
if [ ! -z "$interpreter" ]; then
chmod +x $filename
echo "$comment! /usr/bin/env $interpreter\n$comment " > $filename
fi
# File data
echo "$comment Date: $( date +'%Y/%m/%d' )" >> $filename
echo "$comment Author: $( whoami )" >> $filename
# Compiler
if [ ! -z "$compiler" ]; then
echo "$comment Compiler: $compiler" >> $filename
echo "$comment Compiling: $compiling" >> $filename
fi
# Additional comments
printf "Additional comments: " >&2
read -r additional
if [ ! -z "$additional" ]; then
echo "$comment\n$comment $additional" >> $filename
fi
# Initial default code
echo $init_code >> $filename
$EDITOR $filename
clear && lsd