config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 2fdd8070050fc4d69f2caeb52e3098bde7897be8
parent ebec6d5329ef1cb01fffe023896204c6a5166dba
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Sat, 13 Feb 2021 16:16:14 -0800

Revise mato script

Make general improvements and rewrite in sh(1) since there wasn't
really a benifit to using rc(1) in this case. Also added copywrite
and license header.

Diffstat:
Mmodules/scripts/.local/bin/mato | 64++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/modules/scripts/.local/bin/mato b/modules/scripts/.local/bin/mato @@ -1,36 +1,40 @@ -#!/usr/local/bin/rc -e -#! mato -- add current mpd song to an m3u playlist -#! -#! The current track is added to each file specified, prefixed by mpd's -#! playlist_directory setting, unless it's a duplicate in which case -#! added and a warning is printed to the standard error. +#!/bin/sh +# Copywrite 2021 Jacob R. Edwards +# License: GPLv3 +# +# mato -- add current mpd(1) track to playlist +# +# The current track is appended to each specified playlist if the +# playlist exists and the track is not already contained in it. -ifs = ' -' -progname = `{ basename $0 } +set -e -fn warn { printf '%s: ' $progname; printf $* } -fn err { warn $*; exit 1 } -fn errdup { - awk '-vtrack='^$1 \ - 'length($0) == length(track) && index(track, $0) > 0 { - exit 1 - }' -} +warn() { printf '%s: ' `basename $0` 1>&2 && printf $* 1>&2; } +edup() ! fgrep -qx ${1:-no track} -if (test -z $XDG_CONFIG_HOME) { - config = $HOME/.mpdconf; -} else config = $XDG_CONFIG_HOME/mpd/mpd.conf; +if test -n $XDG_CONFIG_HOME; then + config=$XDG_CONFIG_HOME/mpd/mpd.conf +else + config=$HOME/.mpdconf +fi -dir = `{ grep -m1 '^playlist_directory' $config | cut -d" -f2 \ - | sed 's!^~!'$HOME'!' || err 'playlist_directory undefined\n' } -track = `{ mpc current -f '%file%' } +IFS=' +' +track=`mpc current -f '%file%'` +dir=`grep -m1 '^playlist_directory' $config | cut -d\" -f2 | + sed 's!^~!'$HOME'!'` || { + warn 'unable to get playlist directory\n' + exit 1 +} -for (m3u in $*) { - file = $dir/$m3u.m3u; - if (errdup $track <$file) { +for m3u in $* +do + file="$dir/$m3u.m3u" + if ! test -f $file; then + warn "'%s': No such file or directory.\n" $file + elif ! edup $track <$file; then + warn "'%s': Already contains this track.\n" $m3u + else echo $track >> $file - } else { - warn '''%s'': Already contains this track.\n' $m3u - } -} + fi +done