#!/bin/zsh
# enable with:
#  tmux bind C-a command-prompt -p compose "if-shell \"~/compose.zsh \\\\\\%%\" 'pasteb -d' 'display \"not found\"'"
compose_tbl=/usr/share/X11/locale/en_US.UTF-8/Compose
typeset -A pairs
pairs=(\
	\~ 'dead_tilde\|asciitilde' \
	' ' space \
	\^ 'dead_circumflex\|asciicircum' \
	\\ backslash \
	\| bar \
	: colon \
	, comma \
	\= equal \
	\! exclam \
	\> greater \
	\< less \
	- minus \
	\( parenleft \
	\) parenright \
	. period \
	+ plus \
	\? question \
	\" quotedbl \
	/ slash \
	_ underscore \
	\' apostrophe \
	\` grave \
)
args=()
for ((i=1;$#1-i+1;++i)) {
	args+=('\(<Multi_key> \)\?<\('${${pairs[${1[$i]}]}:-${1[$i]}}'>\)')
}
{grep "^$args\s*:" $compose_tbl||kill $$}|cut -f2 -d:|cut -f2 -d\"|tr -d "\n"|exec tmux loadb -
