aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatherine <shmibs@shmibbles.me>2016-02-01 19:07:08 -0700
committerkatherine <shmibs@shmibbles.me>2016-02-01 19:07:08 -0700
commit0718bee356f08e9f97c311411e1c2c560e5a7758 (patch)
tree1b6390b44b242f000dae8974efcee618b0c32ed1
parent7c09bc77abefc399c39c2afde40220c1f619d179 (diff)
downloaddotfiles-0718bee356f08e9f97c311411e1c2c560e5a7758.tar.gz
mpd-filetypes
-rw-r--r--.zshrc-linux-desktop65
1 files changed, 64 insertions, 1 deletions
diff --git a/.zshrc-linux-desktop b/.zshrc-linux-desktop
index ae926f6..28e251d 100644
--- a/.zshrc-linux-desktop
+++ b/.zshrc-linux-desktop
@@ -4,7 +4,7 @@ alias hc='herbstclient'
################## FUNCTIONS ##################
# power off after finishing mpd playlist
-mpc-sleep() {
+mpd-sleep() {
mpc play
while true; do
mpc status
@@ -15,6 +15,69 @@ mpc-sleep() {
done
}
+# list stats about mpd library file types, to motivate me
+# to do better!
+mpd-filetypes() {
+ total=$(mpc stats | grep Songs | sed 's/Songs: *//')
+
+ # hackily yoink recognised types from mpd --version
+ types=(); mpd --version \
+ | sed -n '1h; 1!H; ${g; s/.*Decoders plugins:\(.*\)Output.*/\1/g; p}'\
+ | tr -s ' ' '\n' | sed -e 's/.*\]//' -e '/^$/d' | sort | uniq | while read word; do
+ types[$(( ${#types} + 1 ))]="$word"
+ done
+ types[$(( ${#types} + 1 ))]="other"
+
+ # find the number of files of each type
+ counts[${#types}]=$total
+ for (( i=1; i < ${#types}; i++ )); do
+ # mpc search is a little faster, but
+ # return bad matches because no regex
+ counts[$i]=$(find ~/music/ -type f -regextype posix-extended -regex ".*\.${types[$i]}" | wc -l)
+ counts[${#types}]=$(( ${counts[${#types}]} - ${counts[$i]} ))
+ done
+
+ twidth=0
+ cwidth=0
+ for (( i=1; i <= ${#types}; i++ )); do
+ if [[ ${counts[$i]} -eq 0 ]]; then
+ percentages[$i]=0
+ else
+ # dunno how to make zsh math float without appending a . to integer numbers
+ percentages[$i]=$(calc -p "${counts[$i]} * 100 / $total" | tr -d '~' | cut -c -4)
+ fi
+
+ # get widths for padding.
+ # exclude when count == 0
+ if [[ ${counts[$i]} -ne 0 ]]; then
+ if [[ ${#types[$i]} -gt $twidth ]]; then
+ twidth=${#types[$i]}
+ fi
+ if [[ ${#counts[$i]} -gt $cwidth ]]; then
+ cwidth=${#counts[$i]}
+ fi
+ fi
+
+ done
+
+ # print non-empty result types
+ for (( i=1; i <= ${#types}; i++ )); do
+ if [[ ${counts[$i]} -ne 0 ]]; then
+ printf "%${twidth}s: " "${types[$i]}"
+ printf "%${cwidth}d" "${counts[$i]}"
+ echo ", %${percentages[$i]}"
+ fi
+ done
+
+ # print total
+ linelen=$(( $twidth + $cwidth + 9 ))
+ for (( i=0; i < $linelen; i++ )); do
+ echo -n "="
+ done
+
+ echo -e "\ntotal: $total"
+}
+
# capture webm
scap() {
archey3