There is xkb-switch which is described thus:
xkb-switch is a C++ program that allows to query and change the XKB layout state.
https://github.com/ierton/xkb-switch
Or, following nozimica's suggestion, you could use:
setxkbmap -print | grep xkb_symbols | awk '{print $4}' | awk -F"+" '{print $2}'
From this thread on the Arch Linux boards: https://bbs.archlinux.org/viewtopic.php?pid=539406