-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmus
More file actions
executable file
·141 lines (125 loc) · 2.63 KB
/
Copy pathmus
File metadata and controls
executable file
·141 lines (125 loc) · 2.63 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
#!/bin/zsh
# In God We Trust †
#
# A.D. MMXXV
setopt EXTENDED_GLOB
_ffind() {
find "$@" -type f -and \( \
-iname "*.mp3" \
-or -iname "*.m4a" \
-or -iname "*.flac" \
-or -iname "*.webm" \
-or -iname "*.mp4" \
-or -iname "*.mkv" \
\)
}
_mus_find() {
(( `printf "$1" | wc -m` < 3 )) \
&& >&2 echo "Try more letters!" \
&& return
# Case-sensitive search
unset cs
echo $1 | grep -q "[A-ZАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ]" && local cs
local fs
if [[ "$1" != */* ]]; then
# Search for directories first
fs=(${(@fo)"$(find "$dir"/ -type d -${cs-i}name "*$1*")"})
# ...then file names
(( ! $#fs )) && fs=(${(@fo)"$(_ffind "$dir"/ -${cs-i}name "*$1*")"})
fi
# ...then path names for dirs
(( ! $#fs )) && fs=(${(@fo)"$(find "$dir"/ -type d -${cs-i}path "*$1*")"})
# ...then path names for files
(( ! $#fs )) && fs=(${(@fo)"$(_ffind "$dir"/ -${cs-i}path "*$1*")"})
while (( $#fs > 1 )) && [[ ! -v list ]]; do
local i=1
for f in $fs; do
>&2 echo $i. ${f#"$dir"/}
i=$((i + 1))
done
>&2 echo
>&2 read \?"Which one? [s"
[ -z "$REPLY" ] && >&2 echo "[uall"
>&2 echo
case "$REPLY" in
all|) break ;;
q) return ;;
*) # The pattern <-> is zsh-ism which matches any string
# having any number of digits and only digits.
if [[ "$REPLY" = <-> ]]; then
fs=("${fs[$REPLY]}")
else
fs=(${(M)fs:#*(#l)$REPLY*})
fi ;;
esac
done
if (( ! $#fs )); then
>&2 echo "No matches found!"
return
fi
for f in $fs; do echo $f; done
}
local dir=${MUS:-~/Music}
while true; do
case "$1" in
s)
local shuffle
echo "Playlist will be shuffled!"
;;
l|lp)
local loop
echo "Loop enabled."
;;
ls)
local list
;;
ly)
fs=(${(@fo)"$(find "$dir"/_lyrics -type f -iname "*$2*.txt")"})
[ -z "$2" ] && echo "${dir/~/~}/_lyrics/"
for f in $fs; do
if [ -z "$2" ]; then
basename ${f%.txt}
else
echo
basename ${f%.txt}
basename ${f%.txt} | sed s/./=/g
echo
column -L $f
echo
fi
done
return 0
;;
*)
break
;;
esac
shift
done
if (( ! $# )); then
ls "$dir"
return
fi
local files=()
while (( $# )); do
files+=(${(@f)"$(_mus_find "$1")"})
shift
done
(( ! $#files )) && return 1
if [[ -v list ]]; then
for f in "${files[@]}"; do
if [[ -d "$f" ]]; then
[[ -v sep ]] && echo
echo "${f#"$dir"/}/"
ls "$f"
sep=2
else
[[ "$sep" == 2 ]] && echo
echo "${f#"$dir"/}"
sep=1
fi
done
else
[ $#files = 1 ] && echo "${files/~/~}"
mpv --title='${chapter-metadata/title:${media-title}}' ${shuffle+--shuffle} ${loop+--loop-playlist} "${files[@]}"
fi