#!/bin/bash
set -e

tf=$(mktemp)
xmodmap -pk -pm > "$tf"
xmodmap -e "keysym $1 = $3 $4 $3 $4" -e "keysym $3 = $1 $2 $1 $2"
echo "Swapped keys $1 $2 with $3 $4, resulting in the following change:"
if diff "$tf" <(xmodmap -pk -pm); then
    echo Error: Ineffective key swap
    exit 1
else
    true
fi
rm "$tf"
