#!/bin/bash exec &>/var/log/gnome-keyboard-toggle-configure.log SERVICE_NAME='gnome-keyboard-toggle-configure.service' GSCHEMA_FILE='/usr/share/glib-2.0/schemas/org.gnome.desktop.wm.keybindings.gschema.override' X11_OPTIONS=$(localectl | awk '{if($0 ~ /X11\s+Options/ ){split($3,arr,",");for(ind in arr) {togl=arr[ind]; sub(/grp:/,"",togl); print togl}}}') SWITCH_INPUT_OPT='' echo "X11_OPTIONS=\"$X11_OPTIONS\"" for X11_OPTION in $X11_OPTIONS; do case "$X11_OPTION" in 'alt_shift_toggle') SWITCH_INPUT_OPT="['Shift_L', 'Alt_R', 'Shift_R', 'Alt_L']"; break ;; 'ctrl_alt_toggle') SWITCH_INPUT_OPT="['Alt_L', 'Control_R', 'Alt_R', 'Control_L']"; break ;; 'ctrl_shift_toggle') SWITCH_INPUT_OPT="['Shift_L', 'Control_R', 'Shift_R', 'Control_L']"; break ;; 'lalt_lshift_toggle') SWITCH_INPUT_OPT="['Shift_L']"; break ;; 'lctrl_lshift_toggle') SWITCH_INPUT_OPT="['Shift_L']"; break ;; 'rctrl_rshift_toggle') SWITCH_INPUT_OPT="['Shift_R']"; break ;; 'alts_toggle') SWITCH_INPUT_OPT="['Alt_L', 'Alt_R']"; break ;; 'ctrls_toggle') SWITCH_INPUT_OPT="['Control_L', 'Control_R']"; break ;; 'shifts_toggle') SWITCH_INPUT_OPT="['Shift_L', 'Shift_R']"; break ;; 'alt_caps_toggle') SWITCH_INPUT_OPT="['Caps_Lock']"; break ;; 'shift_caps_toggle') SWITCH_INPUT_OPT="['Caps_Lock']"; break ;; 'win_space_toggle') SWITCH_INPUT_OPT="['space']"; break ;; *) ;; esac done systemctl disable $SERVICE_NAME [ -z "$SWITCH_INPUT_OPT" ] && exit if [ -f $GSCHEMA_FILE ]; then TMP_FILE=$(mktemp /tmp/gnome-keyboard-toggle-configure_XXXXXXXXX) sed "s/switch-input-source-backward.*$/switch-input-source-backward=${SWITCH_INPUT_OPT}/g" $GSCHEMA_FILE >$TMP_FILE || exit 1 mv -f $TMP_FILE $GSCHEMA_FILE else cat <$GSCHEMA_FILE [org.gnome.desktop.wm.keybindings] switch-input-source-backward=$SWITCH_INPUT_OPT EOF fi glib-compile-schemas /usr/share/glib-2.0/schemas