From 68b2c346f16321bd3a4b94e297bc91d0f2d4f188 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sun, 2 Oct 2022 22:39:52 -0600 Subject: [PATCH] Global mpv keybinds --- bash/.bash_aliases | 4 ++-- mpv/mpv.conf | 1 + sway/config | 17 +++++++++++++++++ sway/mpv_keys.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100755 sway/mpv_keys.sh diff --git a/bash/.bash_aliases b/bash/.bash_aliases index 6465909..cc7a35d 100644 --- a/bash/.bash_aliases +++ b/bash/.bash_aliases @@ -91,8 +91,8 @@ fi if command -v git &> /dev/null; then alias gitst='git status -s' alias gitllog='git log --graph --all --oneline --decorate --color=always | sed -n 1,5p' - alias gitlloga='git log --graph --all --oneline --decorate --color=always | bless' - alias gitllogw='git log --graph --all --date=relative --color=always --pretty="format:%C(auto,yellow)%h%C(auto,magenta) %C(auto,blue)%>(14,trunc)%ad %C(auto,green)%<(13,trunc) %aN%C(auto,red)%gD% D %C(auto,reset)%s" | bless' + alias gitlloga='git log --graph --all --oneline --decorate --color=always | less -R' + alias gitllogw='git log --graph --all --date=relative --color=always --pretty="format:%C(auto,yellow)%h%C(auto,magenta) %C(auto,blue)%>(14,trunc)%ad %C(auto,green)%<(13,trunc) %aN%C(auto,red)%gD% D %C(auto,reset)%s" | less -R' alias gitdesk='github .' alias gitcontrib=' git ls-files | diff --git a/mpv/mpv.conf b/mpv/mpv.conf index 4a83d33..1e08663 100644 --- a/mpv/mpv.conf +++ b/mpv/mpv.conf @@ -7,6 +7,7 @@ save-position-on-quit # Starts from where you left off last time #no-input-default-bindings # Disables all keybinds, including scripts! no-input-builtin-bindings # Disables all default keybinds +input-ipc-server=/tmp/mpvfifo # # Example mpv configuration file diff --git a/sway/config b/sway/config index 5f95cec..5a5b30d 100644 --- a/sway/config +++ b/sway/config @@ -358,6 +358,23 @@ mode "shrink_screenshots" { bindsym Escape mode "default" } +# Global mpv ==== +bindsym $mod2+m mode "mpv_global" + +mode "mpv_global" { + bindsym bracketleft exec ~/.config/sway/mpv_keys.sh '[' + bindsym bracketright exec ~/.config/sway/mpv_keys.sh ']' + bindsym j exec ~/.config/sway/mpv_keys.sh 'j' + bindsym k exec ~/.config/sway/mpv_keys.sh 'k' + bindsym l exec ~/.config/sway/mpv_keys.sh 'l' + bindsym minus exec ~/.config/sway/mpv_keys.sh '-' + bindsym equal exec ~/.config/sway/mpv_keys.sh '=' + + bindsym return mode "default" + bindsym Ctrl+k mode "default" + bindsym Escape mode "default" +} + #╔─────────────────────────────────────────────────────────────────────────────╗ #│ Sτylεs | #╚─────────────────────────────────────────────────────────────────────────────╝ diff --git a/sway/mpv_keys.sh b/sway/mpv_keys.sh new file mode 100755 index 0000000..dd1d95b --- /dev/null +++ b/sway/mpv_keys.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Send a key into mpv. Parses the mpv input.conf to do so +# Sends to pipe named /tmp/mpvfifo unless otherwise specified +# +# Args: +# 1: Key to send +# 2: [Optional] fifo +shopt -s lastpipe + +declare -r KEY="$1" +declare -r FIFO="${2:-/tmp/mpvfifo}" +declare CMD="" + +awk -v k="$KEY " ' +BEGIN { split(k, key, "") } + +{ + is_key = 1 + split($0, a, ""); + + for (i = 1; i <= length(k); i++) + is_key = is_key && (a[i] == key[i]); + + if (is_key) { + if (match($0, /#/)) + print substr($0, length(k)+1, RSTART - length(k) - 1); + else + print substr($0, length(k)+1); + } +}' ~/.config/mpv/input.conf | read -r CMD + +echo "$CMD" | socat "$FIFO" -