-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpdignore.functions
executable file
·462 lines (410 loc) · 18.9 KB
/
mpdignore.functions
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#!/bin/bash
if [[ -z "$TERM" ]]; then
TERM='xterm-256color'
elif [[ "$TERM"=screen* ]]; then
TERM='screen.xterm-256color'
fi
# TERM=screen.xterm-256color #default screen TERM value when calling from cli
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 ;}
pause(){ read -rp "$*"; }
#usermpdpw= #manually define mpd password here
#usermpdmd= #maunally define mpd music directory here
#usermpdpd= #manually define mpd playlist directory here
#usermpdlf= #manually define mpd logfile path here
[[ "$XDG_CONFIG_HOME" ]] &&
. "$XDG_CONFIG_HOME/mpd-local.conf" ||
. /home/"$USER"/.config/mpd-local.conf ||
. /etc/default/mpd-local.conf
watchfile=".mpdignore.m3u" # defines the watched playlist; default = .mpdignore.m3u
mpdconf="/etc/mpd.conf" # defines mpd.conf location; default = /etc/mpd.conf
mpduser="mpd" # defines the user mpd service runs as; default = mpd
mpdgroup="media" # defines the group mpd service runs as; default = media
ignoredm3u="mpdignored.m3u" # defines the playlist of songs ignored by mpdignore; default = mpdignored.m3u
bold="$(tput -T $TERM bold)"
tput0="$(tput -T $TERM sgr0)"
white="$(tput -T $TERM setaf 7)"
red="$(tput -T $TERM setaf 1)"
italics="$(tput -T $TERM sitm)"
ritm="$(tput -T $TERM ritm)"
yellow="$(tput -T $TERM setaf 214)"
blue="$(tput -T $TERM setaf 33)"
mpdc(){
! [[ "$MPD_SOCK" ]] && MPD_SOCK="/var/run/mpd/socket"
local command="$@"
echo -ne "$command\n" | socat - UNIX-CONNECT:"$MPD_SOCK"
}
getmpdconf(){
mpdconf="$(grep MPDCONF /etc/default/mpd)"
mpdconf="${mpdconf#*=}"
}
getmpdpass(){
if [[ -f "$mpdconf" ]] # defines the location of your mpd logfile path; this is defined in the mpd.conf file found at /etc/mpd.conf by default
then
mpdpass="$(grep -v "^#" "$mpdconf" | grep -v "^$" | grep password | grep control | head -n 1)"
mpdpass="${mpdpass%*\"}"
mpdpass="${mpdpass#*\"}"
mpdpass="${mpdpass%\@*}"
else
# read -p "What is the mpd controll password?" mpdpass
mpdpass="$usermpdpw" # manually code the location if /etc/mpd.conf doesn't exist.
fi
}
getmpdmusicdir(){
if [[ -f "$mpdconf" ]] # defines the location of your mpd music directory; this is defi>
then
musicdir=$(grep -v "^#" "$mpdconf" | grep -v "^$" | grep music_directory)
musicdir="${musicdir%*\"}"
musicdir="${musicdir#*\"}"
musicdir="${musicdir%/}"
else
musicdir="$usermpdmd" # manually code the location if /etc/mpd.conf doesn't exist.
fi
}
getmpdpldir(){
if [[ -f "$mpdconf" ]] # defines the location of mpd playlist directory; this is defined in the mpd.conf>
then
pldir=$(grep -v "^#" "$mpdconf" | grep -v "^$" | grep playlist_directory)
pldir="${pldir%*\"}"
pldir="${pldir#*\"}"
pldir="${pldir%/}"
else
pldir="$usermpdpd" # manually code the location if /etc/mpd.conf doesn't exist.
fi
}
getmpdlog() {
if [[ -f "$mpdconf" ]] # defines the location of your mpd logfile path; this is defined>
then
mpdlog=$(grep -v "^#" "$mpdconf" | grep -v "^$" | grep log_file)
mpdlog="${mpdlog%*\"}"
mpdlog="${mpdlog#*\"}"
mpdlog="${mpdlog%/}"
else
mpdlog="$usermpdlf" # manually code the location if /etc/mpd.conf doesn't exist.
fi
}
logsong() {
i=$(date "+%b %d %H:%M : player: $1 ")
[[ "$filepath" ]] && j="$filepath" || j=$(mpcp current -f %file%)
local logged=$(printf '%s\"%s\"\n' "$i" "$j")
# ssh -p "$sshport" "$mpdhost" "echo "${logged@Q}" >> "$mpdlog"" 2>/dev/null
ssh -p "$sshport" "$mpdhost" "printf '%s\\n' ${logged@Q} >> $mpdlog"
# ssh -p "$sshport" "$mpdhost" "echo "$logged" | tee -a "$mpdlog""
}
mpcp() {
# [[ ! -n "$mpdpass" ]] && getmpdpass
[[ -z "$mpdpass" || -z "$mpchost" ]] && . "/$HOME/.config/mpd-local.conf"
# \mpc "${mpdhost:+-h ${mpdpass:+${mpdpass}@}${mpdhost} }""${@}"
#local mpcex=( \mpc "${mpdhost:+-h ${mpdpass:+${mpdpass}@}${mpdhost}}" )
\mpc ${mpchost:+-h ${mpdpass:+"${mpdpass}@"}"${mpchost}"} "$@"
}
mediaduration(){
printf "\nDuration of .mp3 files : "
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
printf "\nDuration of .m4a files : "
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
printf "\nDuration of .m4b files : "
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
printf "\nDuration of .flac files: "
find -type f -iname "*.flac" -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
printf "\nDuration of .mp4 files : "
find -type f -iname "*.mp4" -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
printf "\nDuration of .ogg files : "
find -type f -iname "*.ogg" -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
printf "\nUncomment for .ape files"
# printf "\nDuration of .ape files: "
# find -type f -iname "*.ape" -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
printf "\nDuration of .opus files: "
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
}
title(){
# echo "filepath=$filepath"
# echo "next_filepath=$next_filepath"
# echo "lastfilepath=$lastfilepath"
# echo "lastpath=$lastpath"
c_path_cur=$(tput -T "$TERM" sitm; tput setaf 15) # white path
c_path_que=$(tput -T "$TERM" sitm; tput setaf 7) # pale white
#c_aa=$(tput -T "$TERM" sitm; tput setaf 4) # Blue for artist and album
c_aa_cur=$(tput -T "$TERM" sitm; tput setaf 33) # Blue for artist and album
c_aa_que=$(tput -T "$TERM" sitm; tput setaf 12) # Blue for artist and album
#c_title_cur=$(tput -T "$TERM" sitm; tput setaf 11) # Magenta for the song file name
#c_title_cur=$(tput -T "$TERM" sitm; tput setaf 178) # Magenta for the song file name
c_title_cur=$(tput -T "$TERM" sitm; tput setaf 214) # Yellow for the song name
c_title_que=$(tput -T "$TERM" sitm; tput setaf 3) # Yellow for the song file name
query="$1"
[[ "$query" = skipped ]] && query=current
if [[ "$1" = current ]]; then
printf '%s%s Artist : %s%s%s\n%s Title : %s%s%s\n%s Album : %s%s%s\n' \
"$white" \
"$bold" \
"$c_aa_cur" \
"$artist" \
"$tput0" \
"$bold" \
"$c_title_cur" \
"$title" \
"$tput0" \
"$bold" \
"$c_aa_cur" \
"$album" \
"$tput0"
readarray -d \/ -t file <<< "$filepath"
if (( "${#file[@]}" > 2)); then
printf '%s File : %s%s%s%s%s%s/\n' "$bold" "$tput0" "$c_path_cur" "${file[0]}" "$tput0" "$white" "$bold"
if (( "${#file[@]}" - 3 > 0 )); then
for element in "${file[@]:1:${#file[@]}-3}"; do
# printf ' %s: %s%s/\n' "$white" "$c_path" "$element" "$white"
printf ' : %s%s%s%s%s/\n' "$c_path_cur" "$element" "$tput0" "$white" "$bold"
# printf ' : %s%s%s%s%s/\n' "$c_path_cur" "${file[@]:1:${#file[@]}-3}" "$tput0" "$white" "$bold"
done
fi
printf ' : %s%s%s%s/\n' "$c_aa_cur" "${file[-2]}" "$tput0" "$bold"
printf ' : %s%s%s\n' "$c_title_cur" "${file[-1]%.*}" "$tput0"
elif [[ ! "${file[-2]}" || ! "${file[-1]}" ]] 2>/dev/null; then
printf '%s File %s:%s\n' "$bold" "$c_aa_que" "$tput0"
printf ' %s: %s%s\n' "$bold" "$c_title_que" "$tput0"
else
printf ' File : %s%s%s%s/\n' "$c_aa_cur" "${file[-2]}" "$tput0" "$bold"
printf ' : %s%s%s\n' "$c_title_cur" "${file[-1]%.*}" "$tput0"
fi
elif [[ "$1" = queued ]]; then
printf '%s Artist : %s%s%s%s\n Title : %s%s%s%s\n Album : %s%s%s\n' \
"$white" \
"$c_aa_que" \
"$next_artist" \
"$tput0" \
"$white" \
"$c_title_que" \
"$next_title" \
"$tput0" \
"$white" \
"$c_aa_que" \
"$next_album" \
"$tput0"
readarray -d \/ -t file <<< "$next_filepath"
if (( ${#file[@]} > 2)); then
printf '%s Queued : %s%s%s/\n' "$white" "$c_path" "${file[0]}" "$white"
if (( ${#file[@]} - 3 > 0 )); then
for element in "${file[@]:1:${#file[@]}-3}"; do
printf ' : %s%s%s%s%s/\n' "$c_path_cur" "$element" "$tput0" "$white" "$bold"
done
# printf ' %s: %s%s%s/\n' "$white" "$c_path" "${file[@]:1:${#file[@]}-3}" "$white"
fi
printf ' %s: %s%s%s/\n' "$white" "$c_aa_que" "${file[-2]}" "$tput0"
printf ' %s: %s%s%s\n' "$white" "$c_title_que" "${file[-1]%.*}" "$tput0"
elif [[ ! "${file[-2]}" || ! "${file[-1]}" ]] 2>/dev/null; then
printf '%s Queued %s:%s\n' "$white" "$c_aa_que" "$tput0"
printf ' %s: %s%s\n' "$white" "$c_title_que" "$tput0"
# printf '%s Queued %s: %s%s%s/\n' "$white" "$c_aa_que" "${file[-2]}" "$tput0"
# printf ' %s: %s%s%s\n' "$white" "$c_title_que" "${file[-1]%.*}" "$tput0"
else
printf '%s Queued %s: %s%s%s/\n' "$white" "$c_aa_que" "${file[-2]}" "$tput0"
printf ' %s: %s%s%s\n' "$white" "$c_title_que" "${file[-1]%.*}" "$tput0"
fi
elif [[ "$1" = skipped ]]; then
printf '%s%s Artist %s: %s%s%s\n%s%s Title %s: %s%s%s\n%s%s Album %s: %s%s%s\n' \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_aa_que" \
"$artist" \
"$tput0" \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_title_que" \
"$title" \
"$tput0" \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_aa_que" \
"$album" \
"$tput0"
readarray -d \/ -t file <<< "$filepath"
if (( ${#file[@]} > 2)); then
printf '%s%sSkipped %s%s: %s%s%s/\n' "${st:+$st}" "$white" "$tput0" "$white" "$c_path" "${file[0]}" "$tput0"
if (( ${#file[@]} - 3 > 0 )); then
printf '%s %s%s: %s%s%s/\n' "${st:+$st}" "$tput0" "$white" "$c_path" "${file[@]:1:${#file[@]}-3}" "$tput0"
fi
printf '%s %s%s: %s%s%s/\n' "${st:+$st}" "$white" "$tput0" "$c_aa_que" "${file[-2]}" "$tput0"
printf '%s %s%s: %s%s%s\n' "${st:+$st}" "$white" "$tput0" "$c_title_que" "${file[-1]%.*}" "$tput0"
else
printf '%s%sSkipped %s: %s%s%s/\n' "${st:+$st}" "$white" "$tput0" "$c_aa_que" "${file[-2]}" "$tput0"
printf '%s %s%s: %s%s%s\n' "${st:+$st}" "$white" "$tput0" "$c_title_que" "${file[-1]%.*}" "$tput0"
fi
elif [[ "$1" = last ]]; then
printf '%s%s Artist %s: %s%s%s\n%s%s Title %s: %s%s%s\n%s%s Album %s: %s%s%s\n' \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_aa_que" \
"$lastartist" \
"$tput0" \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_title_que" \
"$lasttitle" \
"$tput0" \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_aa_que" \
"$lastalbum" \
"$tput0"
readarray -d \/ -t file <<< "$lastpath"
if (( ${#file[@]} > 2)); then
printf '%s%s Last %s%s: %s%s%s/\n' \
"${st:+$st}" \
"$white" \
"$tput0" \
"$white" \
"$c_path" \
"${file[0]}" \
"$tput0"
if (( ${#file[@]} - 3 > 0 )); then
printf '%s %s%s: %s%s%s/\n' "${st:+$st}" "$tput0" "$white" "$c_path" "${file[@]:1:${#file[@]}-3}" "$tput0"
fi
printf '%s %s%s: %s%s%s/\n' "${st:+$st}" "$white" "$tput0" "$c_aa_que" "${file[-2]}" "$tput0"
printf '%s %s%s: %s%s%s\n' \
"${st:+$st}" \
"$white" \
"$tput0" \
"$c_title_que" \
"${file[-1]%.*}" \
"$tput0"
else
printf '%s%sSkipped %s: %s%s%s/\n' "${st:+$st}" "$white" "$tput0" "$c_aa_que" "${file[-2]}" "$tput0"
printf '%s %s%s: %s%s%s\n' "${st:+$st}" "$white" "$tput0" "$c_title_que" "${file[-1]%.*}" "$tput0"
fi
fi
}
get-current-json(){
local green="$(tput -T $TERM setaf 10)"
local bold="$(tput -T $TERM bold)"
local tput0="$(tput -T $TERM sgr0)"
local red="$(tput -T $TERM setaf 9)"
current_json=$(/usr/local/bin/mpd-current-json -h "$mpdhost" -p "$mpdport")
state=$(echo "$current_json" | jq -r '.status.state')
song_position=$(echo "$current_json" | jq -r '.status.song_position')
song_length=$(echo "$current_json" | jq -r '.status.playlist_length')
elapsed=$(echo "$current_json" | jq -r '.status.elapsed')
total_time=$(echo "$current_json" | jq -r '.status.duration')
percent_time=$(echo "$current_json" | jq -r '.status.elapsed_percent')
filepath=$(echo "$current_json" | jq -r '.filename')
# filepath=$(echo "$current_json" | jq -r '.tags.filename')
# songpath=$(echo "$current_json" | jq -r '.tags.filename')
title=$(echo "$current_json" | jq -r '.tags.title')
artist=$(echo "$current_json" | jq -r '.tags.artist')
album_artist=$(echo "$current_json" | jq -r '.tags.album_artist')
album=$(echo "$current_json" | jq -r '.tags.album')
year=$(echo "$current_json" | jq -r '.tags.date')
volume=$(echo "$current_json" | jq -r '.status.volume')
repeat=$(echo "$current_json" | jq -r '.status.repeat')
single=$(echo "$current_json" | jq -r '.status.single')
random=$(echo "$current_json" | jq -r '.status.random')
consume=$(echo "$current_json" | jq -r '.status.consume')
next_filepath=$(echo "$current_json" | jq -r '.next_filename')
mb_artistid=$(echo "$current_json" | jq -r '.tags.musicbrainz_artistid')
mb_albumid=$(echo "$current_json" | jq -r '.tags.musicbrainz_albumid')
mb_trackid=$(echo "$current_json" | jq -r '.tags.musicbrainz_trackid')
mb_reltrackid=$(echo "$current_json" | jq -r '.tags.musicbrainz_releasetrackid')
# [[ "$repeat" = true ]] && repeat="✅" || repeat="❌"
[[ "$repeat" = true ]] && repeat="${bold}${green}⟳${tput0}" || repeat="$(tput -T $TERM setaf 7)⟳${tput0}"
[[ "$consume" = true ]] && consume="${bold}✅${tput0}" || consume="${bold}❌${tput0}"
[[ "$random" = true ]] && random="${bold}✅${tput0}" || random="${bold}❌${tput0}"
[[ "$single" = true ]] && single="✅" || unset single
[[ "$state" = playing ]] && state="${green}${bold}$state${tput0}" || [[ "$state" = paused ]] && state="${red}${state}${tput0}"
printmpcjson() {
echo -ne "${name:+Name: $name\n}"
echo -ne "${title:+ Title: $title\n}"
echo -ne "${artist:+ Artist: $artist\n}"
echo -ne "${album:+ Album: $album\n}"
echo -ne "${year:+ Year: $year\n}"
echo -ne "${album_artist:+AlbmArt: $album_artist\n}"
echo -ne "${comment:+Comment: $comment\n}"
# echo -ne "${composer:+Composer: $composer\n}"
echo -ne "${date:+ Date: $date\n}"
# echo -ne "${originaldate:+Original Date: $originaldate\n}"
echo -ne "${disc:+ Disc: $disc\n}"
echo -ne "${genre:+ Genre: $genre\n}"
echo -ne "${performer:+Performer: $performer\n}"
echo -ne "${track:+ Track: $track\n}"
echo -ne "${mb_artistid:+mbartid: $mb_artistid\n}"
echo -ne "${mb_albumid:+mbalbid: $mb_albumid\n}"
echo -ne "${mb_trackid:+mbtrkid: $mb_trackid\n}"
echo -ne "${mb_reltrackid:+mbreltk: $mb_reltrackid\n}"
echo -ne "${time:+ Time: $time\n}"
echo -ne "${state:+ State: $state\n}"
echo -ne "${volume:+ Volume: $volume\n}"
echo -ne "${song_position:+ Queue: $song_position\n}"
echo -ne "${elapsed:+ Time: $(sec2sex $elapsed)}"
echo -ne "${total_time:+ $(sec2sex $total_time)}"
echo -ne "${percent_time:+ (${percent_time%.*}%)\n}"
echo -ne "${repeat:+ Repeat: $repeat\n}"
echo -ne "${random:+ Random: $random\n}"
echo -ne "${single:+ Single: $single\n}"
echo -ne "${consume:+Consume: $consume\n}"
echo -ne "${filepath:+Current: $filepath\n}"
echo -ne "${next_filepath:+ Next: $next_filepath\n}"
}
# printmpcjson
}
sec2sex() {
local h m s
local input="${1%.*}"
local dec="${1#*.}"; dec="${dec:0:1}"
[[ "$dec" > 4 ]] && ((input++))
h=$(( input / 3600 ))
m=$(( (input % 3600) / 60 ))
s=$(( input % 60 ))
if (( h > 0 )); then
printf "%02d:%02d:%02d" "$h" "$m" "$s"
else
printf "%d:%02d" "$m" "$s"
fi
}
hr2() {
local width="$(tput -T $TERM cols)"
local status="$1"
local left_padding="${2:-22}"
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() {
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"
}
[[ "$1" == @(edit|e|nano|-e|-E) ]] && editscript