forked from naryal2580/shebang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shebang.sh
executable file
·94 lines (75 loc) · 1.51 KB
/
shebang.sh
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
#!/bin/bash
arguments="${@:2}" # because, 1st arg. is the filename
fullname="$PWD/$1"
fulfname="${fullname##*/}" # Full File Name :p
extension="${fulfname##*.}"
filename="${fulfname%.*}"
tmpffname="$PWD/$filename$RANDOM.$extension"
tmpfname="${tmpffname%.*}"
if type "zsh" > /dev/null; then
good_sh="zsh"
elif type "bash" > /dev/null; then
good_sh="bash"
else
line=$(cat /etc/passwd | grep $(whoami))
good_sh=${x##*/}
fi
rmshbng() {
# $i may later be used, as it counts lines read..
while IFS= read -r line; do
if [[ $i == "" ]] && [[ $line == *shebang* ]]; then
line=""
fi
echo "$line" >> "$tmpffname"
i=$((i+1))
done < "$fullname"
# This thing, `\n`++ incase, theres none @ bottom
[ -n "$line" ] && echo '' >> "$tmpffname"
}
case $extension in
py | pyc)
python3 $fullname $arguments
;;
rs)
rmshbng
rustc $tmpffname
$tmpfname $arguments
rm $tmpffname
rm $tmpfname
;;
sh | bash | zsh)
$good_sh $fullname $arguments
;;
go)
rmshbng
go run $tmpffname $arguments
rm $tmpffname
;;
c)
gcc -o $tmpfname $filename
$tmpfname $arguments
;;
js)
rmshbng
node $tmpffname $arguments
rm $tmpffname
;;
rb)
rmshbng
ruby $tmpffname $arguments
rm $tmpffname
;;
fish)
fish $fullname $arguments
;;
"") # a JIC* case [*Just in case]
# this is a fin' rare case ;)
$main_sh $fullname $arguments
;;
*)
if [[ $filename != *.* ]]; then # if no extension
$good_sh $fullname $arguments
else
echo "$extension not supported yet..";
fi
esac