我认为这个脚本应该可以设置键绑定,但它目前很无聊——更新:它已经被取消了,现在可以工作了。不过它很丑,我正在寻求使它更优雅的方法,因为每次我想要一个新的键绑定时都需要复制粘贴四行。
我声称由于 zsh 不支持 2d 数组,我可能最好在 python 中重写它......更新,python 脚本就在这里
如何正确设置键绑定的问题就在这里。
#!/bin/zsh
# How many keybinds?
N=16
# Put keybindings here
k0=("keyboard dvorak nocaps" "Menu" "setxbmap dvorak -option nocaps")
k1=("launch code" "<Super>c" "code")
k2=("dropdown firefox" "<Shift><Super>f" "tdrop -ma -h \"100%\" -w \"50%\" firefox")
mkeys="org.gnome.settings-daemon.plugins.media-keys"
_locstr="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom"
_ck="$mkeys.custom-keybinding:$_locstr"
M="$(expr $N - 1)"
# Create spaces for $N keybindings, emulating the command:
# gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/ media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ ']"
locations=""
for i in $(seq 0 $M); do
locations+="'$_locstr$i/', "
done
locations+="'$_locstr$N/' "
gsettings set $mkeys custom-keybindings "[$locations]"
# issue commands. Have to paste 4 lines each time, kinda gross.
ck="${_ck}0/"
gsettings set $ck name $k0[1]
gsettings set $ck binding $k0[2]
gsettings set $ck command $k0[3]
ck="${_ck}1/"
gsettings set $ck name $k1[1]
gsettings set $ck binding $k1[2]
gsettings set $ck command $k1[3]
ck="${_ck}2/"
gsettings set $ck name $k2[1]
gsettings set $ck binding $k2[2]
gsettings set $ck command $k2[3]
# test with:
# i=0
# ck="${_ck}$i/"
# gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings
# gsettings list-recursively $ck
一些改进途径: