I have a script to:
Set the keyboard layout to include accents
Set capslock as mod when held
Set capslock as escape when pressed
It looks like this:
setxkbmap -rules evdev -model evdev -layout us -variant altgr-intl &
sleep 1
xmodmap ~/.Xmodmap &
sleep 1
killall -q xcape &
xcape -e "Hyper_L=Escape" &
Those sleep
are there because otherwise it doesn't work well. I don't understand why and I'd love to. In addition to that, sometimes the escape part of it just stops working, and I have to relaunch the script. I'm not exactly sure what triggers this but it is annoying.