From 97b27287f5e9a83ade58bd269184dd9b3134cd92 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Thu, 12 Jan 2023 11:31:23 +0100 Subject: [PATCH] MPV: Extract socket path from command line --- mpv.controller.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mpv.controller.sh b/mpv.controller.sh index 487685c..908c0cd 100755 --- a/mpv.controller.sh +++ b/mpv.controller.sh @@ -3,15 +3,13 @@ # Purpose {{{ # This script will try to control MPV with IPC socket # 1. Check for MPV proc with IPC socket option. -# 2. Verify if a process runs with one of the expected socket. -# Unable to correctly extract socket path from command line… +# 2. Extract the newest socket path from command line. # 3. Send user command to the last MPV process with a existing socket. # # 2022-05-22 # }}} # TODO {{{ # * Add an option to set the socket path. -# * Set a list of sockets path and use the first existing one. # * Add new user command ? # }}} # Vars {{{ @@ -24,9 +22,10 @@ readonly NBARGS="${#}" export DEBUG ## Default values for some vars -readonly MPV_PROC_REGEXP="mpv.*--input-ipc-server" +readonly MPV_PROC_REGEXP="mpv.*--input-ipc-server=" readonly USER_MULTIMEDIA_COMMAND_DEFAULT="toggle" -readonly MPV_POSSIBLE_SOCKET_PATH="${HOME}/.cache/qutebrowser/mpv.ipc.socket" +MPV_POSSIBLE_SOCKET_PATH=$(pgrep --newest --full --list-full -- "^${MPV_PROC_REGEXP}" | sed -n -e "s/.*${MPV_PROC_REGEXP}\(.*\) .*/\1/p;q") +readonly MPV_POSSIBLE_SOCKET_PATH ## Colors readonly PURPLE='\033[1;35m' @@ -91,8 +90,6 @@ error_message() { # {{{ define_vars() { # {{{ ## Get the socket path of the last MPV process {{{ - ## Can't extract a valid socket path from the command line ! - ## So… no other choice than test a static list of possible socket MPV_SOCKET_PATH="${MPV_POSSIBLE_SOCKET_PATH}" debug_message "define_vars − \ IPC socket path for the last MPV process : ${RED}${MPV_SOCKET_PATH}${COLOR_DEBUG} ."