diff options
author | A Farzat <a@farzat.xyz> | 2024-10-24 22:54:21 +0900 |
---|---|---|
committer | A Farzat <a@farzat.xyz> | 2024-11-04 22:54:21 +0900 |
commit | c68ac8e8d7524dcb448b7970ab7dacef93c47a4a (patch) | |
tree | 87d18ff1e684ea74309c045cfa07e9272b7cfb5d /bin/dmenu/tmux_umpv | |
parent | 4c457acbd55c6e935f822a1c7208f8a53f248beb (diff) | |
download | dotfiles-c68ac8e8d7524dcb448b7970ab7dacef93c47a4a.tar.gz dotfiles-c68ac8e8d7524dcb448b7970ab7dacef93c47a4a.zip |
Add some dmenu scripts
Diffstat (limited to 'bin/dmenu/tmux_umpv')
-rwxr-xr-x | bin/dmenu/tmux_umpv | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bin/dmenu/tmux_umpv b/bin/dmenu/tmux_umpv new file mode 100755 index 0000000..eb2b4e6 --- /dev/null +++ b/bin/dmenu/tmux_umpv @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +# Open links using mpv in a new tmux window while setting the socket name to selection. +# If the chosen socket is already active, load the urls to the mpv instance instead. +# Make sure the urls are printed as they are added. + +sock_dir="${MPV_SOCKET_DIR:-$XDG_RUNTIME_DIR/mpv/sockets}" +[ -d "$sock_dir" ] || mkdir -p "$sock_dir" +sock="$(find "$sock_dir" -maxdepth 1 -mindepth 1 -type s -printf "%f\n" | dmenu -p "Choose mpv instance:")" +[ -z "$sock" ] && exit 1 + +if printf '{ "command": ["get_property", "path"] }\n' | nc -NU "$sock_dir/$sock" >/dev/null 2>&1; then + for link in "$@"; do + [ -e "$link" ] && link="$(realpath -s "$link")" + jq -cn --arg l "$link" '{"command":["loadfile",($l),"append"]},{"command":["print-text","LOADFILE:= "+($l)]}' + done | nc -NU "$sock_dir/$sock" >/dev/null +else + tmux neww -t mpv: mpv --volume=50 --script-opts=mpv_socket="$sock",print_filenames=yes "$@" +fi |