MPV: Extract socket path from command line

This commit is contained in:
gardouille 2023-01-12 11:31:23 +01:00
parent f2528c963f
commit 97b27287f5
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 4 additions and 7 deletions

View File

@ -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} ."