Global mpv keybinds

This commit is contained in:
Akemi Izuko 2023-12-23 20:13:53 -07:00
parent f6e7684ea9
commit 4ead70bf68
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
4 changed files with 52 additions and 2 deletions

View file

@ -91,8 +91,8 @@ fi
if command -v git &> /dev/null; then if command -v git &> /dev/null; then
alias gitst='git status -s' alias gitst='git status -s'
alias gitllog='git log --graph --all --oneline --decorate --color=always | sed -n 1,5p' 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 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" | 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" | less -R'
alias gitdesk='github .' alias gitdesk='github .'
alias gitcontrib=' alias gitcontrib='
git ls-files | git ls-files |

View file

@ -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-default-bindings # Disables all keybinds, including scripts!
no-input-builtin-bindings # Disables all default keybinds no-input-builtin-bindings # Disables all default keybinds
input-ipc-server=/tmp/mpvfifo
# #
# Example mpv configuration file # Example mpv configuration file

View file

@ -358,6 +358,23 @@ mode "shrink_screenshots" {
bindsym Escape mode "default" 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 | #│ Sτylεs |
#╚─────────────────────────────────────────────────────────────────────────────╝ #╚─────────────────────────────────────────────────────────────────────────────╝

32
sway/mpv_keys.sh Executable file
View file

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