#!/bin/sh
set -e
if [ -z "${XDG_CONFIG_HOME}" -a ! -z "${HOME}" ]
then
	XDG_CONFIG_HOME="${HOME}/.config"
fi
if [ -z "${XDG_CONFIG_HOME}" ]
then
	echo "error: $0: needs environment variable 'XDG_CONFIG_HOME' but is not present.">&2
	exit 1
fi
mkdir -p "${XDG_CONFIG_HOME}/xkb/keymap"
mkdir -p "${XDG_CONFIG_HOME}/xkb/symbols"
cd "${XDG_CONFIG_HOME}/xkb/symbols"
rm -f math
rm -f anticaps
rm -f emdash
rm -f thinkpad
wget http://www.scratchpost.org/software/keyboard/math_key/Xorg/usr/share/X11/xkb/symbols/math
wget http://www.scratchpost.org/software/keyboard/math_key/Xorg/usr/share/X11/xkb/symbols/anticaps
wget http://www.scratchpost.org/software/keyboard/math_key/Xorg/usr/share/X11/xkb/symbols/emdash
wget http://www.scratchpost.org/software/keyboard/math_key/Xorg/usr/share/X11/xkb/symbols/thinkpad
## thinkpad
setxkbmap -print >"${XDG_CONFIG_HOME}/xkb/keymap/dannym1"
sed -i -e 's;\(xkb_symbols.*include "\)\([^"]*\)\(.*\)$;\1\2+math+anticaps+emdash+thinkpad\3;' -e 's;+us+;+us(intl)+;' "${XDG_CONFIG_HOME}/xkb/keymap/dannym1"
exec xkbcomp -I"${XDG_CONFIG_HOME}/xkb" "${XDG_CONFIG_HOME}/xkb/keymap/dannym1" :0
