-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileLauncher
executable file
·71 lines (65 loc) · 2.01 KB
/
fileLauncher
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
#!/bin/bash
r() {
# initialisation
unset filename
mkdir -p ~/.temp ~/.temp/last
touch ~/.temp/last/script
last_script=$(cat ~/.temp/last/script)
# checking target
if [[ -n "$1" ]]; then
if [[ -f "$1" ]]; then
basename=$(basename -- "$1")
filename="${1%%.*}"
ext=".${1##*.}"
printf "$(pwd)/$1" > ~/.temp/last/script
pwd='.'
else
echo "Target is not accessible"
fi
elif [[ -f "$last_script" ]]; then
basename=$(basename -- "$last_script")
filename="${basename%%.*}"
ext=".${basename##*.}"
pwd=$(pwd)
cd $(dirname "$last_script")
else
if [[ "$last_script" == *"/data/data/com.termux/files/home"* ]]; then
readablePath=$(sed 's:\/data\/data\/com\.termux\/files\/home:\~:g' <<< "$last_script")
fi
echo "Last target is not accessible"
echo "($readablePath)"
fi
# executing target
if [[ -n "$filename" ]]; then
if [[ ! "$basename" == *"."* ]]; then
unset ext
fi
if [[ $(head -c 3 "$filename$ext") == "#!/" || "$ext" == ".sh" ]]; then
chmod +x "$filename$ext" && ./"$filename$ext" "${@:2}"
elif [[ "$ext" == ".c" ]]; then
({ while kill -0 "$$"; do sleep 10; done; rm "$filename.exe"; } > /dev/null 2>&1 &)
gcc -Wall -Wextra -Werror "$filename$ext" -o "$filename".exe -lm \
&& (sleep 1 && rm "$filename".exe &) \
&& ./"$filename".exe "${@:2}"
elif [[ "$ext" == ".exe" ]]; then
exec ./"$filename$ext" "${@:2}"
elif [[ "$ext" == ".java" ]]; then
({ while kill -0 "$$"; do sleep 10; done; rm "$filename.class"; } > /dev/null 2>&1 &)
proot javac "$filename.java" \
&& (sleep 1 && rm "$filename.class" &) \
&& proot java "$filename" "${@:2}"
elif [[ "$ext" == ".class" ]]; then
proot java "$filename" "${@:2}"
elif [[ "$ext" == ".py" ]]; then
python3 "$filename$ext" "${@:2}"
elif [[ "$ext" == ".jar" ]]; then
java -jar "$filename$ext" "${@:2}"
else
echo "File type isn't supported"
fi
fi
}
# go back
b() {
cd "$pwd"
}