-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexopus.lib
More file actions
executable file
·317 lines (266 loc) · 11.3 KB
/
indexopus.lib
File metadata and controls
executable file
·317 lines (266 loc) · 11.3 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
# nb: the swp file that editscript relies on is provided by nano
scriptpath="$(realpath "$0" 2>/dev/null)"
script="${scriptpath##*\/}"
ulon="$(tput smul)" #underline on
uloff="$(tput rmul)" #underline off
red="$(tput setaf 9)" #red fg
green="$(tput setaf 2)" #green fg
white="$(tput setaf 15)" #white fg
tput0="$(tput sgr0)" #reset tput changes
bold="$(tput bold)" #bold on
boldred="$(tput setaf 9 bold)"
relipsis="$red..."
mediagroup='media'
tlpp(){
local scriptname="${0##*/}"
local shells="^bash|^init|^screen|^sh|^ssh|^su|${scriptname}"
local pid=${1:-$$}
local pidname="`ps --no-heading -o %c -p ${pid}`"
local stat=($(</proc/${pid}/stat))
tlpp_ppid=${stat[3]}
local ppidname="`ps --no-heading -o %c -p ${tlpp_ppid}`"
isclitest="`echo "${ppidname}" | grep -iv -E "${shells}"`"
until [ "${tlpp_ppid}" -eq "1" ] || [ "${iscli}" = "1" ]; do
if [[ -n "${isclitest}" ]]; then
iscli="1"
else
iscli="0"
tlpp ${tlpp_ppid}
fi
done
[[ "$iscli" ]] && return "$iscli"
}
#editscript(){
# local scriptpath script path swp; scriptpath=$(realpath "$0" 2>/dev/null); script="${scriptpath##*/}"; path="${scriptpath%/*}"; swp="$path/.$script.swp"
# [[ ! -e "$swp" ]] && printf "\n\n%s\n\n" "$swp" && (/usr/bin/nano "$scriptpath") && exit
# printf "\n%s is already being edited.\n%s exists; try fg or look in another window.\n" "$scriptpath" "$swp"; exit ; }
[[ -r /usr/local/bin/editscript ]] && source /usr/local/bin/editscript
if ! command -v own &> /dev/null; then
own(){
if [[ $(pwd) = "/library/"* ]] || [[ $(pwd) = "$HOME"* ]] || [[ $(pwd) = "/dev/shm/cache"* ]] || [[ "$1" = "--force" ]]; then
sudo find . ! -user "$USER" ! -iname metadata.json -exec chown -R "$USER":media "{}" \;
sudo find . ! -group "$mediagroup" -exec chgrp -R "$mediagroup" "{}" \;
sudo find . -type d ! -perm 775 -exec chmod 775 "{}" \;
sudo find . -type f ! -perm 664 -exec chmod 664 "{}" \;
sudo chown "$USER":"$mediagroup" .
fi
}
fi
confirm(){
local def prompt reply msg empty
while [[ $# -gt 0 ]]; do
case $1 in
-1)
empty=1
shift
;;
-y|-Y|-n|-N)
def="${1#-}"
shift
;;
-d|--default)
def="$2"
shift 2
;;
--default=*)
def="${1#*=}"
shift 1
;;
--)
shift
break
;;
-*)
echo "Unknown option: $1" >&2
return 2
;;
*)
break
;;
esac
done
# msg=$1
msg="$(printf -- %b "$1")"
shift
case $def in
y|Y) prompt=" [Y/n] "; def=y ;;
n|N) prompt=" [y/N] "; def=n ;;
*) prompt=" [y/n] "; def= ;;
esac
(( empty )) && prompt="${prompt# }"
read -p "$msg$prompt" -n 1 -r reply
printf \\n
reply=${reply:-$def}
[[ $reply =~ ^[Yy]$ ]]
}
printline(){
local lead linetitle leader strippedleader leader_length remaining_width line endlines
#line="$(printf '%s%*s\n' "$red" "$(tput cols)"|tr ' ' "-")$tput0"
[[ "$1" ]] && linetitle="$1" ||
linetitle="${bold} $scriptpath $tput0"
# Allow for "$1" to contain `\n`s to pad the line before...
while [[ "$linetitle" = "\n"* ]]; do
printf \\n
linetitle="${linetitle#\\n}"
done
# ...And after
while [[ "$linetitle" = *"\n" ]]; do
(( endlines++ ))
linetitle="${linetitle%\\n}"
done
# Define the lead including formatting
lead="${red}—————————${white}${bold}"
# Define the title and leader including formatting
leader="$lead$linetitle"
# Strip control characters from the leader
strippedleader=$(printf '%s' "$leader" | perl -pe 's/\e\[?.*?[\@-~]//g')
# Calculate the remaining width after accounting for the leader
remainingwidth=$(( $(tput cols) - ${#strippedleader} ))
# Construct the line
# line="${leader}${red}$(printf '%*s' "$remainingwidth" | tr ' ' '—')${tput0}"
line="${leader}${red}$(printf '%*s' "$remainingwidth" '' | sed 's/ /—/g')${tput0}"
printf %s\\n "$line"
for (( i=0; i<endlines; i++ )); do
printf \\n
done
}
##--> printline() <--################################################################
hr2(){
local width="$(tput -T $TERM cols)"
local status=""
local left_padding=22
# Determine the status and padding based on the input
if [[ "$1" = "--center" ]]; then
status="$2"
left_padding=$(( (width - ${#status} - 2) / 2 ))
elif [[ "$2" == "--center" ]]; then
status="$1"
left_padding=$(( (width - ${#status} - 2) / 2 ))
elif [[ "$1" =~ ^[0-9]+$ ]]; then
status="$2"
left_padding="$1"
elif [[ "$2" =~ ^[0-9]+$ ]]; then
status="$1"
left_padding="$2"
elif [[ "$1" == "center" || "$2" == "center" ]]; then
if [[ "$1" == "center" ]]; then
status="$2"
else
status="$1"
fi
left_padding=$(( (width - ${#status} - 2) / 2 ))
else
status="$1"
left_padding="${2:-22}"
fi
local left_dashes=$(printf -- '%.0s—' $(seq 1 "$left_padding"))
local right_dashes=$(printf -- '%.0s—' $(seq 1 "$((width - left_padding - ${#status} - 2))"))
printf '%s %s %s\n' "$left_dashes" "$status" "$right_dashes"
}
##--> hr2() <--################################################################
sex2sec(){
local time="$1";
[[ ! "$time" =~ [[:digit:]]{2,3}:[[:digit:]]{2}:[[:digit:]]{2} ]] && time='00:00:00' #&& pause "${time@A}"
local hours=$(echo "$time" | awk -F: '{print $1}'); #pause "$hours"
local minutes=$(echo "$time" | awk -F: '{print $2}'); #pause "$minutes"
local seconds=$(echo "$time" | awk -F: '{print $3}'); #pause "$seconds"
local total_seconds=$(( (10#$hours * 3600) + (10#$minutes * 60) + (10#$seconds) ));
# pause "no sec $(local total_seconds=$(( (10#$hours * 3600) + (10#$minutes * 60) )) )"
# pause "no min $(local total_seconds=$(( (10#$hours * 3600) + (10#$seconds) )) )"
# pause "no hours $(local total_seconds=$(( (10#$minutes * 60) + (10#$seconds) )) )"
echo "$total_seconds" ; }
##--> sex2sec() <--##################################################################
checkdur(){ #came from opus.book.4 #refactored below to be more concise.
local m4as m4bs opuss mp3s checkdurexts
checkdurexts='@(m4a|m4b|mp3|opus)'
m4as=(*m4a)
m4bs=(*m4b)
opuss=(*opus)
mp3s=(*mp3)
if [[ "$1" = $checkdurexts ]]; then
find -type f -iname "*.$1" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null |
perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' |
tail -n 1
elif [[ "$1" = *.$checkdurexts ]]; then
printf '%s%s %s\n%s' "$red" "$(mplayer -vo dummy -ao dummy -identify "$1" 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1)" "$1" "$tput0"
else
printf '\n%sDuration(s):%s\n' "$bold" "$tput0"
[[ "${#m4as[@]}" -gt 0 ]] &&
printf '%s %s%s%s %s%s\n' "$bold" "$red" "$(find -type f -iname "*.m4a" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1)" "$white" "${m4as[@]}" "$tput0"
[[ "${#m4bs[@]}" -gt 0 ]] &&
printf '%s %s%s%s %s%s\n' "$bold" "$red" "$(find -type f -iname "*.m4b" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1)" "$white" "${m4bs[@]}" "$tput0"
[[ "${#mp3s[@]}" -gt 0 ]] &&
printf '%s %s%s%s %s%s\n' "$bold" "$red" "$(find -type f -iname "*.mp3" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1)" "$white" "${mp3s[@]}" "$tput0"
[[ "${#opuss[@]}" -gt 0 ]] &&
printf '%s %s%s%s %s%s\n' "$bold" "$red" "$(find -type f -iname "*.opus" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1)" "$white" "${opuss[@]}" "$tput0"
fi
}
##--> checkdur() <--###########################################################################
# Refactored on Tue Jan 14 07:41:06 AM EST 2025; the above may eventually be eliminated.
checkdur(){ # from opus.book.4
local m4as m4bs opuss mp3s checkdurexts
checkdurexts='@(m4a|m4b|mp3|opus)'
m4as=(*m4a); [[ ! -f "${m4as[0]}" ]] && unset m4as
m4bs=(*m4b); [[ ! -f "${m4bs[0]}" ]] && unset m4bs
mp3s=(*mp3); [[ ! -f "${mp3s[0]}" ]] && unset mp3s
opuss=(*opus); [[ ! -f "${opuss[0]}" ]] && unset opuss
findmedia(){ find -type f -iname "*.$1" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null; }
perldur(){ perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1; }
if [[ "$1" = $checkdurexts ]]; then
findmedia "$1" | perldur
elif [[ "$1" = *.$checkdurexts ]]; then
printf '%s%s %s\n%s' "$red" "$(mplayer -vo dummy -ao dummy -identify "$1" 2>/dev/null | perldur)" "$1" "$tput0"
else
printf '\n%sDuration(s):%s\n' "$bold" "$tput0"
[[ "${m4as[@]}" ]] &&
printf 'm4a: %s %s%s %s%s\n' "$boldred" "$(findmedia m4a | perldur)" "$white" "${m4as[@]}" "$tput0"
[[ "${m4bs[@]}" ]] &&
printf 'm4b: %s %s%s %s%s\n' "$boldred" "$(findmedia m4b | perldur)" "$white" "${m4bs[@]}" "$tput0"
[[ "${mp3s[@]}" ]] &&
printf 'mp3: %s %s%s %s%s\n' "$boldred" "$(findmedia mp3 | perldur)" "$white" "${mp3s[@]}" "$tput0"
[[ "${opuss[@]}" ]] &&
printf 'opus: %s %s%s %s%s\n' "$boldred" "$(findmedia opus | perldur)" "$white" "${opuss[@]}" "$tput0"
fi
}
##--> checkdur() <--###########################################################################
fnboobs(){
echo "( • )( • )----ԅ(‾⌣‾ԅ)"
}
##--> fnboobs() <--###########################################################################
##--> indexopus.lib <--###########################################################################
##--> Main Code <--###########################################################################
#tlpp; echo "$? $0 $iscli"
#[[ -t 1 ]] && echo "[[ -t 1 ]] returned true"
#read -rp "$?"
#https://mywiki.wooledge.org/BashFAQ/109
#if [[ $- != *i* ]]; then
# echo "Run from cli"
#fi
#<emanuele6> like, a shell is not interactive when $- != *i*
#<emanuele6> it is interactive when $- = *i*
#<iconoclast_hero> i understood more what you meant by internative...
#<emanuele6> you can also check $- = *i* && $- = *s* for interactive shell that is reading stdin
#<emanuele6> and you can add $- = *i* && $- = *s* && -t 0 for interactive shell that is reading directly from a terminal via stdin
##if [[ $- != *i* ]]; then
# echo "$0 believes it was called from the cli!"
#fi
#if tlpp || [[ "${0##*/}" = "indexopus.lib" ]] || [[ $- != *i* ]]; then
#tlpp
#if [[ $? ]]; then
if [[ $- = *i* && $- = *s* && -t 0 ]]; then
echo "$0 believes it was called from the cli!"
unalias pause 2>/dev/null
[[ "$apause" ]] && echo "unaliased $apause"
alias mpause="mpcP pause"
printline
fi
pause(){ read -rp "$*" ;}
#ps -o stat= -p $$
#ps -o stat= -p $PPID
#printf '%s %s\n' "$(ps -o stat= -p $$)" "$(ps -o stat= -p $PPID)"
#pause "$(ps -o stat= -p $$) $(ps -o stat= -p $PPID)"
#pause "$( [[ -t 1 ]] && echo terminal || echo script)"
#printline
#pause "$(ps -o stat= -p $PPID) $(ps -o stat= -p $$)"
[[ "$1" == @(edit|e|nano|-e|-E) ]] && editscript