-
Notifications
You must be signed in to change notification settings - Fork 0
/
localFileUtils
executable file
·115 lines (103 loc) · 2.71 KB
/
localFileUtils
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
#!/bin/bash
# initialisation
if [[ -d '/sdcard/Download' ]]; then
ub='/data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu/root'
mkdir -p /sdcard/Download/Shared
fi
# bulk rename
ren() {
readarray -t files <<< $(find)
for ((i=0; i < "${#files[@]}"; i++)); do
renammed=$(sed -E "s:$1:$2:g" <<< "${files[i]}")
mv "${files[i]}" "$renammed" 2> /dev/null
done
}
catall() {
find . -type f -exec cat {} +
}
# average time of command
avg() {
calc=0
if [[ -z "$1" || -z "$2" ]]; then
echo 'Usage : avg <times> <command>'
else
echo
times="$1"
command="${@:2}"
for ((i=0; i < "$times"; i++)); do
time=$((time $command > /dev/null 2>&1) 2>&1)
calc+="+${time:8:-28}"
echo -e "\e[A$i/$1"
done
time=$(bc <<< 'scale=3;('"$calc"')/'"$times"'*1000')
echo -e "\e[A${time:0:-4}ms"
fi
}
# zip content listing
7zl() {
7za l "$1" | tail -n+21 | head -n-2 | awk '{print $5}' | grep -v -e ^'0'$ -e '.git/' -e 'node_modules/' | tail -n+2
}
# share files TO vm (PROOT-DISTRO)
shrvm() {
cp -r "$1" "$ub"/
}
# get files FROM vm (PROOT-DISTRO)
getvm() {
cp -r "$ub"/"$1" ~/
}
# shares files0 TO Shared folder (TERMUX)
shr() {
if [[ -d /sdcard/Download/Shared ]]; then
cp -r "$1" /sdcard/Download/Shared
else
echo "Feature only supported on termux"
fi
}
# get files FROM Shared folder (TERMUX)
get() {
if [[ -d /sdcard/Download/ ]]; then
cp -r /sdcard/Download/"$1" ./
else
echo "Feature only supported on termux"
fi
}
# move files TO Shared folder (TERMUX)
shrmv() {
if [[ -d /sdcard/Download/Shared ]]; then
mv "$1" /sdcard/Download/Shared/;
else
echo "Feature only supported on termux"
fi
}
# move files FROM Shared folder (TERMUX)
getmv() {
if [[ -d /sdcard/Download/ ]]; then
mv /sdcard/Download/"$1" ./
else
echo "Feature only supported on termux"
fi
}
# extend m3u file (ANDROID)
extendm3u() {
unset allM3U regularM3U rawM3U
readarray -t allM3U <<< $(find /sdcard/Music/ -type f -name "*.m3u")
for i in "${allM3U[@]}"; do
if [[ $(head -n 1 "$i") != '#EXTM3U' ]]; then
m3uLocation="$(readlink -f $i)"
folderLocation="${m3uLocation%/*}"
outputLocation="$i"
# outputLocation="${i%.*}-extended.m3u"
readarray -t lines <<< $(egrep -o '.+\.opus|.+\.mp3|.+\.m4a|.+\.aac|.+\.3gp|.+\.wav' "$i")
echo "Extended $i (${#lines[@]} songs)"
# echo "Extended $i to $outputLocation (${#lines[@]} songs)"
rawM3U=('#EXTM3U')
for j in "${lines[@]}"; do
rawM3U+=("#EXTINF:-1,${j%.*}" "$folderLocation/$j")
done
printf '%s\n' "${rawM3U[@]}" > "$outputLocation"
fi
done
if [[ -z "${rawM3U[@]}" ]]; then
echo "No non-extended m3u files found"
fi
}