Blob
Date:
Thu Mar 3 13:50:12 2022
UTC
Message:
rework how the daemon is automatically spawned
The previous way introduce possible races if multiple `amused' instances
try to start the daemon.
The new approach is heavily lifted from how tmux does it, but with some
minor differences. If the initial connect fails we try to grab a lock
to safely execute the daemon only one time. In fact we try to connect
one more time even when we hold the lock because another instance can
grab the lock, start the daemon and release it between the failure of
connect and the first flock.
It also changes slightly how the program behaves and how the -d option
works. Now running `amused' without arguments is a synonym for `amused
status' and the -d option only works if no arguments were given and if
the daemon wasn't running.
.\" Copyright (c) 2022 Omar Polo <op@openbsd.org>.\".\" Permission to use, copy, modify, and distribute this software for any.\" purpose with or without fee is hereby granted, provided that the above.\" copyright notice and this permission notice appear in all copies..\".\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE..\".Dd March 3, 2022.Dt AMUSED 1.Os.Sh NAME.Nm amused.Nd music player.Sh SYNOPSIS.Nm.Op Fl dv.Op Fl s Ar socket.Oo.Ar command.Op Ar argument ....Oc.Sh DESCRIPTION.Nmis a music player daemon and command-line utility that plays musicin the background.The server is automatically started when the user interacts withit..PpThe following options are available:.Bl -tag -width 12m.It Fl dDo not daemonize if starting the daemon:.Nmwill run in the foreground and log to standard error.It's ignored if any commands are given on the command line or if theserver was already running..It Fl vProduce more verbose output..It Fl s Ar socketUse.Ar socketinstead of the default.Pa /tmp/amused-$UIDto communicate with the daemon..It Ar command Op Ar argument ...Specify the command to run.If no commands are specified, the.Ic statuscommand is assumed..El.PpThe following commands are available:.Bl -tag -width 12m.It Cm add ArEnqueue the given files..It Cm flushErase the playlist..It Cm jump Ar patternPlay the first song in the playing queue that matches.Ar pattern.Pq a basic case-insensitive regexp ..It Cm load Op Ar fileLoad a playlist from.Ar fileor standard input.A playlist is a list of paths to music files one per line optionallyprefixed by.Sq > \&or two spaces.If the list was generated by.Nm.Ic show Fl prestores also the currently playing song..It Cm monitorStop indefinitely and print the events as happen.Events are print one per line and are triggered either by otherinstances of.Nmissuing commands or the player itself anvancing the playing queue..It Cm nextPlay the next song..It Cm pausePause the playback..It Cm playStart or resume the playback..It Cm prevPlay the previous song..It Cm repeat one|all on|offEnable or disable the repetition of the current track.Pq Cm oneor of the playing queue.Pq Cm all ..It Cm restartRewind the current song to the beginning..It Cm show Op Fl pPrint the current playlist.With.Fl pit prints a.Dq prettylist with the current playing song prefixed by.Sq > \& ..It Cm statusPrint playback status and current song..It Cm stopStop the music player..It Cm togglePlay/pause the playback..El.PpCommands can be abbreviated to the smallest unique prefix, for example.Sq repcan be given instead of.Sq repeat ..Sh FILES.Bl -tag -width "/tmp/amused-$UID" -compact.It Pa /tmp/amused-$UID.Ux Ns -domainsocket used for communication with the daemon..El.Sh EXAMPLESEnqueue all mp3 files in the current directory:.Bd -literal -offset indent$ amused add *.mp3.Ed.PpRecursively add all opus files:.Bd -literal -offset indent$ find . -type f -iname \\*.opus -exec amused add {} +.Ed.PpSave the state of the player to the file.Pa state :.Bd -literal -offset indent$ amused show -p > state.Ed.PpLoad a previous state:.Bd -literal -offset indent$ amused load < state.Ed.PpRandomize the current playlist:.Bd -literal -offset indent$ amused show | sort -R | amused load.Ed.PpRemove duplicates:.Bd -literal -offset indent$ amused show | sort | uniq | amused load.Ed.PpSelect a song with.Xr fzf 1.Bd -literal -offset indent$ amused jump "$(amused show | fzf +s)".Ed.Sh AUTHORS.An -nosplitThen.Nmutility was written by.An Omar Polo Aq Mt op@openbsd.org ..Sh BUGS.Nmlooks at the file name to determine the file type,.Xr magic 5should be used instead.
Omar Polo